Skip to content

Commit

Permalink
Improve inline docs and method names
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Nov 18, 2024
1 parent 11f3bcb commit d11d3dd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
31 changes: 16 additions & 15 deletions panel/src/components/Views/ModelView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ export default {
this.$events.on("keydown.left", this.toPrev);
this.$events.on("keydown.right", this.toNext);
this.$events.on("model.reload", this.$reload);
this.$events.on("view.save", this.onSubmitShortcut);
this.$events.on("view.save", this.onViewSave);
},
destroyed() {
this.$events.off("beforeunload", this.onBeforeUnload);
this.$events.off("content.save", this.onContentSave);
this.$events.off("keydown.left", this.toPrev);
this.$events.off("keydown.right", this.toNext);
this.$events.off("model.reload", this.$reload);
this.$events.off("view.save", this.onSubmitShortcut);
this.$events.off("view.save", this.onViewSave);
},
methods: {
onBeforeUnload(e) {
Expand All @@ -92,37 +92,38 @@ export default {
},
async onDiscard() {
await this.$panel.content.discard(this.api);
this.$panel.view.reload();
this.$panel.view.refresh();
},
onInput(values) {
// update the content for the current view
// this will also refresh the content prop
this.$panel.content.update(values, this.api);
this.$panel.content.saveLazy(values, this.api);
// trigger a throttled save call with the updated content
this.$panel.content.saveLazy(this.content, this.api);
},
async onSubmit(values = {}) {
if (length(values) > 0) {
this.$panel.content.update(values, this.api);
}
async onSubmit() {
await this.$panel.content.publish(this.content, this.api);
this.$panel.notification.success();
this.$events.emit("model.update");
// the view needs to be refreshed to get an updated set of props
// this will also rerender sections if needed
await this.$panel.view.refresh();
},
onSubmitShortcut(e) {
onViewSave(e) {
e?.preventDefault?.();
this.onSubmit();
},
toPrev(e) {
if (this.prev && e.target.localName === "body") {
this.$go(this.prev.link);
}
},
toNext(e) {
if (this.next && e.target.localName === "body") {
this.$go(this.next.link);
}
},
toPrev(e) {
if (this.prev && e.target.localName === "body") {
this.$go(this.prev.link);
}
}
}
};
Expand Down
11 changes: 9 additions & 2 deletions panel/src/panel/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default (panel) => {
* @returns {Object}
*/
changes(api = panel.view.props.api) {
// changes can only be computed for the current view
if (this.isCurrent(api) === false) {
throw new Error("Cannot get changes from another view");
}
Expand All @@ -39,6 +40,8 @@ export default (panel) => {
return;
}

// In the current view, we can use the existing
// lock state to determine if we can discard
if (this.isCurrent(api) === true && this.isLocked(api) === true) {
throw new Error("Cannot discard locked changes");
}
Expand All @@ -48,6 +51,7 @@ export default (panel) => {
try {
await panel.api.post(api + "/changes/discard");

// update the props for the current view
if (this.isCurrent(api)) {
panel.view.props.content = panel.view.props.originals;
}
Expand Down Expand Up @@ -87,7 +91,7 @@ export default (panel) => {
lock(api = panel.view.props.api) {
if (this.isCurrent(api) === false) {
throw new Error(
"The lock state cannot be detected for content from in another view"
"The lock state cannot be detected for content from another view"
);
}

Expand All @@ -102,6 +106,8 @@ export default (panel) => {
return;
}

// In the current view, we can use the existing
// lock state to determine if changes can be published
if (this.isCurrent(api) === true && this.isLocked(api) === true) {
throw new Error("Cannot publish locked changes");
}
Expand All @@ -112,11 +118,12 @@ export default (panel) => {
try {
await panel.api.post(api + "/changes/publish", values);

// update the props for the current view
if (this.isCurrent(api)) {
panel.view.props.originals = panel.view.props.content;
}

panel.events.emit("content.publish", { api, values });
panel.events.emit("content.publish", { values, api });
} finally {
this.isProcessing = false;
}
Expand Down

0 comments on commit d11d3dd

Please sign in to comment.