1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-08-08 15:05:26 +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>}
*/
static async get(aliasName) {
const alias = await Alias.get(aliasName.slice(1));
const alias = await Alias.get(aliasName);
if (!alias.id) {
throw new Error('Entity with given alias does not exist');

View file

@ -117,21 +117,25 @@ class Pages {
if (!page._id) {
throw new Error('Page with given id does not exist');
}
const oldAlias = page.uri;
const previousUri = page.uri;
page.data = data;
const pagePromise = page.save();
const updatedPage = await pagePromise;
Alias.markAsDeprecated(oldAlias);
if (updatedPage.uri !== previousUri) {
Alias.markAsDeprecated(previousUri);
const alias = new Alias({
id: updatedPage._id,
type: aliasTypes.PAGE,
hash: md5(updatedPage.uri)
});
const alias = new Alias({
id: updatedPage._id,
type: aliasTypes.PAGE,
hash: md5(updatedPage.uri)
});
alias.save();
}
alias.save();
return pagePromise;
}

View file

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

View file

@ -18,3 +18,13 @@
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-line-gray: #E8E8EB;
--color-link-active: #388AE5;
--color-gray-border: rgba(201, 201, 204, 0.48);
/**
* Site layout sizes

View file

@ -26,7 +26,11 @@ class Alias {
*/
static async get(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);
}

View file

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

View file

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

View file

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

View file

@ -9,7 +9,7 @@
<section data-module="writing">
<module-settings hidden>
{
"page": {{ page | json_encode }}
"page": {{ page | json_encode }}
}
</module-settings>
<header class="writing-header">
@ -23,7 +23,7 @@
<option value="0">Root</option>
{% for _page in pagesAvailable %}
{% 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 }}
</option>
{% endif %}
@ -34,5 +34,10 @@
Save
</span>
</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>
{% endblock %}