1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-08-09 07:25:21 +02:00

Added ability to change uri manually

This commit is contained in:
DorofeevMark 2018-12-21 08:49:35 +03:00
parent 77f671b052
commit bdd5da4ec6
12 changed files with 47 additions and 21 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -13,7 +13,7 @@ class Aliases {
* @returns {Promise<Alias>} * @returns {Promise<Alias>}
*/ */
static async get(aliasName) { static async get(aliasName) {
const alias = await Alias.get(aliasName.slice(1)); const alias = await Alias.get(aliasName);
if (!alias.id) { if (!alias.id) {
throw new Error('Entity with given alias does not exist'); throw new Error('Entity with given alias does not exist');

View file

@ -117,13 +117,15 @@ class Pages {
if (!page._id) { if (!page._id) {
throw new Error('Page with given id does not exist'); throw new Error('Page with given id does not exist');
} }
const oldAlias = page.uri; const previousUri = page.uri;
page.data = data; page.data = data;
const pagePromise = page.save(); const pagePromise = page.save();
const updatedPage = await pagePromise; const updatedPage = await pagePromise;
Alias.markAsDeprecated(oldAlias); if (updatedPage.uri !== previousUri) {
Alias.markAsDeprecated(previousUri);
const alias = new Alias({ const alias = new Alias({
id: updatedPage._id, id: updatedPage._id,
@ -132,6 +134,8 @@ class Pages {
}); });
alias.save(); alias.save();
}
return pagePromise; return pagePromise;
} }

View file

@ -27,7 +27,8 @@ export default class Writing {
this.nodes = { this.nodes = {
editorWrapper: null, editorWrapper: null,
saveButton: null, saveButton: null,
parentIdSelector: null parentIdSelector: null,
uriInput: null
}; };
} }
@ -61,6 +62,7 @@ export default class Writing {
this.saveButtonClicked(); this.saveButtonClicked();
}); });
this.nodes.parentIdSelector = moduleEl.querySelector('[name="parent"]'); this.nodes.parentIdSelector = moduleEl.querySelector('[name="parent"]');
this.nodes.uriInput = moduleEl.querySelector('[name="uri-input"]');
}; };
/** /**
@ -91,6 +93,7 @@ export default class Writing {
return { return {
parent: this.nodes.parentIdSelector.value, parent: this.nodes.parentIdSelector.value,
uri: this.nodes.uriInput ? this.nodes.uriInput.value : '',
body: editorData body: editorData
}; };
} }

View file

@ -18,3 +18,13 @@
color: var(--color-text-second); color: var(--color-text-second);
} }
} }
.uri-input {
border: 1px solid rgba(201, 201, 204, 0.48);
box-shadow: inset 0 1px 2px 0 rgba(35, 44, 72, 0.06);
border-radius: 3px;
padding: 10px 12px;
outline: none;
width: 100%;
box-sizing: border-box;
}

View file

@ -3,6 +3,7 @@
--color-text-second: #7B7E89; --color-text-second: #7B7E89;
--color-line-gray: #E8E8EB; --color-line-gray: #E8E8EB;
--color-link-active: #388AE5; --color-link-active: #388AE5;
--color-gray-border: rgba(201, 201, 204, 0.48);
/** /**
* Site layout sizes * Site layout sizes

View file

@ -26,7 +26,11 @@ class Alias {
*/ */
static async get(aliasName) { static async get(aliasName) {
const hash = md5(aliasName); const hash = md5(aliasName);
const data = await aliasesDb.findOne({hash}); let data = await aliasesDb.findOne({hash: hash, deprecated: false});
if (!data) {
data = await aliasesDb.findOne({hash: hash});
}
return new Alias(data); return new Alias(data);
} }

View file

@ -148,11 +148,11 @@ class Page {
* @returns {Promise<Page>} * @returns {Promise<Page>}
*/ */
async save() { async save() {
let newUri = translateString(this.title.toLowerCase()).split(' ').join('-'); let newUri = this.uri;
let pageWithSameUri = await Page.getByUri(newUri); let pageWithSameUri = await Page.getByUri(newUri);
let pageWithSameUriCount = 0; let pageWithSameUriCount = 0;
while (pageWithSameUri._id) { while (pageWithSameUri._id && pageWithSameUri._id !== this._id) {
pageWithSameUriCount++; pageWithSameUriCount++;
pageWithSameUri = await Page.getByUri(newUri + `-${pageWithSameUriCount}`); pageWithSameUri = await Page.getByUri(newUri + `-${pageWithSameUriCount}`);
} }

View file

@ -11,8 +11,7 @@ const aliasTypes = require('../constants/aliasTypes');
*/ */
router.get('*', async (req, res) => { router.get('*', async (req, res) => {
try { try {
console.log('url ', req.originalUrl); const alias = await Aliases.get(req.originalUrl.slice(1));
const alias = await Aliases.get(req.originalUrl);
switch (alias.type) { switch (alias.type) {
case aliasTypes.PAGE: { case aliasTypes.PAGE: {

View file

@ -76,8 +76,8 @@ router.post('/page/:id', multer.any(), async (req, res) => {
const {id} = req.params; const {id} = req.params;
try { try {
const {title, body, parent} = req.body; const {title, body, parent, uri} = req.body;
const page = await Pages.update(id, {title, body, parent}); const page = await Pages.update(id, {title, body, parent, uri});
res.json({ res.json({
success: true, success: true,

View file

@ -23,7 +23,7 @@
<option value="0">Root</option> <option value="0">Root</option>
{% for _page in pagesAvailable %} {% for _page in pagesAvailable %}
{% if _page._id != currentPageId %} {% if _page._id != currentPageId %}
<option value="{{ _page._id }}" {{ page is not empty and page._parent == _page._id ? 'selected' : ''}}> <option value="{{ _page._id }}" {{ page is not empty and page._parent == _page._id ? 'selected' : '' }}>
{{ _page.title }} {{ _page.title }}
</option> </option>
{% endif %} {% endif %}
@ -34,5 +34,10 @@
Save Save
</span> </span>
</header> </header>
{% if page is not empty %}
<main>
<input type="text" class="uri-input" name="uri-input" placeholder="Uri(Optional)" value="{{ page.uri }}">
</main>
{% endif %}
</section> </section>
{% endblock %} {% endblock %}