FIX: Correctly shows no bookmark message (#9548)
This commit is contained in:
parent
2c6d6dfd05
commit
ad978b93ab
|
@ -2,6 +2,7 @@ import Controller from "@ember/controller";
|
||||||
import showModal from "discourse/lib/show-modal";
|
import showModal from "discourse/lib/show-modal";
|
||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
import { inject } from "@ember/controller";
|
import { inject } from "@ember/controller";
|
||||||
|
import { action } from "@ember/object";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import Bookmark from "discourse/models/bookmark";
|
import Bookmark from "discourse/models/bookmark";
|
||||||
|
|
||||||
|
@ -22,12 +23,8 @@ export default Controller.extend({
|
||||||
|
|
||||||
return this.model
|
return this.model
|
||||||
.loadItems()
|
.loadItems()
|
||||||
.then(response => {
|
.then(response => this._processLoadResponse(response))
|
||||||
this.processLoadResponse(response);
|
.catch(() => this._bookmarksListDenied())
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
this.set("noResultsHelp", I18n.t("bookmarks.list_permission_denied"));
|
|
||||||
})
|
|
||||||
.finally(() =>
|
.finally(() =>
|
||||||
this.setProperties({
|
this.setProperties({
|
||||||
loaded: true,
|
loaded: true,
|
||||||
|
@ -38,69 +35,72 @@ export default Controller.extend({
|
||||||
|
|
||||||
@discourseComputed("loaded", "content.length", "noResultsHelp")
|
@discourseComputed("loaded", "content.length", "noResultsHelp")
|
||||||
noContent(loaded, contentLength, noResultsHelp) {
|
noContent(loaded, contentLength, noResultsHelp) {
|
||||||
return loaded && contentLength === 0 && noResultsHelp !== null;
|
return loaded && contentLength === 0 && noResultsHelp;
|
||||||
},
|
},
|
||||||
|
|
||||||
processLoadResponse(response) {
|
@action
|
||||||
response = response.user_bookmark_list;
|
removeBookmark(bookmark) {
|
||||||
|
bootbox.confirm(I18n.t("bookmarks.confirm_delete"), result => {
|
||||||
|
if (result) {
|
||||||
|
return bookmark.destroy().then(() => this.loadItems());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
if (response && response.no_results_help) {
|
@action
|
||||||
this.set("noResultsHelp", response.no_results_help);
|
editBookmark(bookmark) {
|
||||||
|
let controller = showModal("bookmark", {
|
||||||
|
model: {
|
||||||
|
postId: bookmark.post_id,
|
||||||
|
id: bookmark.id,
|
||||||
|
reminderAt: bookmark.reminder_at,
|
||||||
|
name: bookmark.name
|
||||||
|
},
|
||||||
|
title: "post.bookmarks.edit",
|
||||||
|
modalClass: "bookmark-with-reminder"
|
||||||
|
});
|
||||||
|
controller.setProperties({
|
||||||
|
afterSave: () => this.loadItems()
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
@action
|
||||||
|
loadMore() {
|
||||||
|
if (this.loadingMore) {
|
||||||
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.set("loadingMore", true);
|
||||||
|
|
||||||
|
return this.model
|
||||||
|
.loadMore()
|
||||||
|
.then(response => this._processLoadResponse(response))
|
||||||
|
.catch(() => this._bookmarksListDenied())
|
||||||
|
.finally(() => this.set("loadingMore", false));
|
||||||
|
},
|
||||||
|
|
||||||
|
_bookmarksListDenied() {
|
||||||
|
this.set("noResultsHelp", I18n.t("bookmarks.list_permission_denied"));
|
||||||
|
},
|
||||||
|
|
||||||
|
_processLoadResponse(response) {
|
||||||
|
if (!response) {
|
||||||
|
this._bookmarksListDenied();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.no_results_help) {
|
||||||
|
this.set("noResultsHelp", response.no_results_help);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
response = response.user_bookmark_list;
|
||||||
this.model.more_bookmarks_url = response.more_bookmarks_url;
|
this.model.more_bookmarks_url = response.more_bookmarks_url;
|
||||||
|
|
||||||
if (response && response.bookmarks) {
|
if (response.bookmarks) {
|
||||||
let bookmarks = [];
|
this.content.pushObjects(
|
||||||
response.bookmarks.forEach(bookmark => {
|
response.bookmarks.map(bookmark => Bookmark.create(bookmark))
|
||||||
bookmarks.push(Bookmark.create(bookmark));
|
);
|
||||||
});
|
|
||||||
this.content.pushObjects(bookmarks);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
removeBookmark(bookmark) {
|
|
||||||
bootbox.confirm(I18n.t("bookmarks.confirm_delete"), result => {
|
|
||||||
if (result) {
|
|
||||||
return bookmark.destroy().then(() => this.loadItems());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
editBookmark(bookmark) {
|
|
||||||
let controller = showModal("bookmark", {
|
|
||||||
model: {
|
|
||||||
postId: bookmark.post_id,
|
|
||||||
id: bookmark.id,
|
|
||||||
reminderAt: bookmark.reminder_at,
|
|
||||||
name: bookmark.name
|
|
||||||
},
|
|
||||||
title: "post.bookmarks.edit",
|
|
||||||
modalClass: "bookmark-with-reminder"
|
|
||||||
});
|
|
||||||
controller.setProperties({
|
|
||||||
afterSave: () => this.loadItems()
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
loadMore() {
|
|
||||||
if (this.loadingMore) {
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
this.set("loadingMore", true);
|
|
||||||
|
|
||||||
return this.model
|
|
||||||
.loadMore()
|
|
||||||
.then(response => this.processLoadResponse(response))
|
|
||||||
.catch(() => {
|
|
||||||
this.set("noResultsHelp", I18n.t("bookmarks.list_permission_denied"));
|
|
||||||
})
|
|
||||||
.finally(() =>
|
|
||||||
this.setProperties({
|
|
||||||
loadingMore: false
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
import { acceptance } from "helpers/qunit-helpers";
|
||||||
|
import selectKit from "helpers/select-kit-helper";
|
||||||
|
import pretender from "helpers/create-pretender";
|
||||||
|
|
||||||
|
acceptance("User's bookmarks", {
|
||||||
|
loggedIn: true,
|
||||||
|
|
||||||
|
beforeEach() {
|
||||||
|
pretender.delete("/bookmarks/576", () => [
|
||||||
|
200,
|
||||||
|
{ "Content-Type": "application/json" },
|
||||||
|
{}
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("listing user bookmarks", async assert => {
|
||||||
|
await visit("/u/eviltrout/activity/bookmarks-with-reminders");
|
||||||
|
|
||||||
|
assert.ok(find(".bookmark-list-item").length);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("removing a bookmark", async assert => {
|
||||||
|
await visit("/u/eviltrout/activity/bookmarks-with-reminders");
|
||||||
|
|
||||||
|
const dropdown = selectKit(".bookmark-actions-dropdown");
|
||||||
|
await dropdown.expand();
|
||||||
|
await dropdown.selectRowByValue("remove");
|
||||||
|
|
||||||
|
assert.ok(exists(".bootbox.modal"));
|
||||||
|
|
||||||
|
await click(".bootbox.modal .btn-primary");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("listing users bookmarks - no bookmarks", async assert => {
|
||||||
|
pretender.get("/u/eviltrout/bookmarks.json", () => [
|
||||||
|
200,
|
||||||
|
{
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
bookmarks: [],
|
||||||
|
no_results_help: "no bookmarks"
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
await visit("/u/eviltrout/activity/bookmarks-with-reminders");
|
||||||
|
|
||||||
|
assert.equal(find(".alert.alert-info").text(), "no bookmarks");
|
||||||
|
});
|
Loading…
Reference in New Issue