Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat(store): new function for renaming pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Palmaswell authored and lkuechler committed Feb 15, 2018
1 parent cad182b commit 73413d2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/store/project/page-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ export class PageRef {
this.setProject(undefined);
}

/*
* Sets the technical (internal) ID of the page.
*/
public setId(id: string): void {
this.id = id;
}

/**
* Sets the human-friendly name of the page.
*/
public setName(name: string): void {
this.name = name;
}

/**
* Sets the project this page belongs to.
* If it belonged to a project before, it is removed from that project.
Expand Down
17 changes: 17 additions & 0 deletions src/store/store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PatternFolder } from './pattern/folder';
import * as FileUtils from 'fs';
import { JsonArray, JsonObject, Persister } from './json';
import * as MobX from 'mobx';
import { IObservableArray } from 'mobx/lib/types/observablearray';
Expand Down Expand Up @@ -427,6 +428,22 @@ export class Store {
(this.projects as IObservableArray<Project>).remove(project);
}

/**
* Renames the name of the pages files and update the names
* @param id The new ID of the page.
*/

public renamePage(id: string): void {
if (this.currentPage) {
const oldPath = PathUtils.join(
this.styleGuidePath,
`/alva/page-${this.currentPage.getId()}.yaml`
);
const newPath = PathUtils.join(this.styleGuidePath, `/alva/page-${id}.yaml`);
FileUtils.renameSync(oldPath, newPath);
}
}

/**
* Saves the entire store. This includes the project definitions and page references and
* the currently opened page and its elements.
Expand Down

0 comments on commit 73413d2

Please sign in to comment.