diff --git a/Web/Models/Entities/Note.php b/Web/Models/Entities/Note.php index e15a838c..b33f1238 100644 --- a/Web/Models/Entities/Note.php +++ b/Web/Models/Entities/Note.php @@ -94,4 +94,9 @@ class Note extends Postable return $cached; } + + function getSource(): string + { + return $this->getRecord()->source; + } } diff --git a/Web/Presenters/NotesPresenter.php b/Web/Presenters/NotesPresenter.php index 443a484a..d88c6365 100644 --- a/Web/Presenters/NotesPresenter.php +++ b/Web/Presenters/NotesPresenter.php @@ -67,6 +67,35 @@ final class NotesPresenter extends OpenVKPresenter $note->setCreated(time()); $note->setName($this->postParam("name")); $note->setSource($this->postParam("html")); + $note->setEdited(time()); + $note->save(); + + $this->redirect("/note" . $this->user->id . "_" . $note->getVirtualId()); + } + } + + function renderEdit(int $owner, int $note_id): void + { + $this->assertUserLoggedIn(); + $this->willExecuteWriteAction(); + + $note = $this->notes->getNoteById($owner, $note_id); + + if(!$note || $note->getOwner()->getId() !== $owner || $note->isDeleted()) + $this->notFound(); + if(is_null($this->user) || !$note->canBeModifiedBy($this->user->identity)) + $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); + $this->template->note = $note; + + if($_SERVER["REQUEST_METHOD"] === "POST") { + if(empty($this->postParam("name"))) { + $this->flashFail("err", tr("error"), tr("error_segmentation")); + } + + $note->setName($this->postParam("name")); + $note->setSource($this->postParam("html")); + $note->setCached_Content(NULL); + $note->setEdited(time()); $note->save(); $this->redirect("/note" . $this->user->id . "_" . $note->getVirtualId()); diff --git a/Web/Presenters/templates/Notes/Edit.xml b/Web/Presenters/templates/Notes/Edit.xml new file mode 100644 index 00000000..1544fbc1 --- /dev/null +++ b/Web/Presenters/templates/Notes/Edit.xml @@ -0,0 +1,47 @@ +{extends "../@layout.xml"} + +{block title}{_edit_note}{/block} + +{block header} + {var author = $note->getOwner()} + {$author->getCanonicalName()} + » + {_notes} + » + {$note->getName()} +{/block} + +{block content} +
+ + {script "js/node_modules/monaco-editor/min/vs/loader.js"} + {script "js/node_modules/requirejs/bin/r.js"} + +{/block} diff --git a/Web/Presenters/templates/Notes/View.xml b/Web/Presenters/templates/Notes/View.xml index 8813d4e3..6c57d1c0 100644 --- a/Web/Presenters/templates/Notes/View.xml +++ b/Web/Presenters/templates/Notes/View.xml @@ -44,6 +44,7 @@ diff --git a/Web/routes.yml b/Web/routes.yml index e22f938e..7bd01965 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -223,6 +223,8 @@ routes: handler: "Notes->view" - url: "/notes/create" handler: "Notes->create" + - url: "/note{num}_{num}/edit" + handler: "Notes->edit" - url: "/note{num}_{num}/delete" handler: "Notes->delete" - url: "/invite" diff --git a/locales/en.strings b/locales/en.strings index 0f4d8fc7..ee2e9081 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -295,8 +295,11 @@ "name_note" = "Title"; "text_note" = "Content"; "create_note" = "Create note"; +"edit_note" = "Edit note"; "actions" = "Actions"; +"edited" = "Edited"; + "notes_zero" = "No notes"; "notes_one" = "$1 note"; "notes_other" = "$1 notes"; diff --git a/locales/ru.strings b/locales/ru.strings index 64f66185..bee9b7cc 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -313,8 +313,11 @@ "name_note" = "Название"; "text_note" = "Содержание"; "create_note" = "Создать заметку"; +"edit_note" = "Редактировать заметку"; "actions" = "Действия"; +"edited" = "Отредактировано"; + "notes_zero" = "Ни одной заметки"; "notes_one" = "Одна заметка"; "notes_few" = "$1 заметки";