Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 559c0a8e authored by Julie Thezenas's avatar Julie Thezenas
Browse files

new test in top and last

parent dafa853e
No related tags found
No related merge requests found
import {
navigateToTopic,
showEntrance,
} from "discourse/components/topic-list-item";
import Component from "@ember/component";
import discourseComputed from "discourse-common/utils/decorators";
export default Component.extend({
attributeBindings: ["topic.id:data-topic-id"],
classNameBindings: [":latest-topic-list-item", "unboundClassNames"],
showEntrance,
navigateToTopic,
click(e) {
// for events undefined has a different meaning than false
if (this.showEntrance(e) === false) {
return false;
}
return this.unhandledRowClick(e, this.topic);
},
// Can be overwritten by plugins to handle clicks on other parts of the row
unhandledRowClick() {},
@discourseComputed("topic")
unboundClassNames(topic) {
let classes = [];
if (topic.get("category")) {
classes.push("category-" + topic.get("category.fullSlug"));
}
if (topic.get("tags")) {
topic.get("tags").forEach((tagName) => classes.push("tag-" + tagName));
}
["liked", "archived", "bookmarked", "pinned", "closed", "visited"].forEach(
(name) => {
if (topic.get(name)) {
classes.push(name);
}
}
);
return classes.join(" ");
},
});
\ No newline at end of file
import { alias, and, reads } from "@ember/object/computed";
import discourseComputed, { observes } from "discourse-common/utils/decorators";
import Component from "@ember/component";
import LoadMore from "discourse/mixins/load-more";
import discourseDebounce from "discourse-common/lib/debounce";
import { on } from "@ember/object/evented";
import { schedule } from "@ember/runloop";
import showModal from "discourse/lib/show-modal";
export default Component.extend(LoadMore, {
tagName: "table",
classNames: ["topic-list"],
classNameBindings: ["bulkSelectEnabled:sticky-header"],
showTopicPostBadges: true,
listTitle: "topic.title",
canDoBulkActions: and("currentUser.staff", "selected.length"),
// Overwrite this to perform client side filtering of topics, if desired
filteredTopics: alias("topics"),
_init: on("init", function () {
this.addObserver("hideCategory", this.rerender);
this.addObserver("order", this.rerender);
this.addObserver("ascending", this.rerender);
this.refreshLastVisited();
}),
@discourseComputed("bulkSelectEnabled")
toggleInTitle(bulkSelectEnabled) {
return !bulkSelectEnabled && this.canBulkSelect;
},
@discourseComputed
sortable() {
return !!this.changeSort;
},
skipHeader: reads("site.mobileView"),
@discourseComputed("order")
showLikes(order) {
return order === "likes";
},
@discourseComputed("order")
showOpLikes(order) {
return order === "op_likes";
},
@observes("topics.[]")
topicsAdded() {
// special case so we don't keep scanning huge lists
if (!this.lastVisitedTopic) {
this.refreshLastVisited();
}
},
@observes("topics", "order", "ascending", "category", "top")
lastVisitedTopicChanged() {
this.refreshLastVisited();
},
scrolled() {
this._super(...arguments);
let onScroll = this.onScroll;
if (!onScroll) {
return;
}
onScroll.call(this);
},
scrollToLastPosition() {
if (!this.scrollOnLoad) {
return;
}
let scrollTo = this.session.get("topicListScrollPosition");
if (scrollTo && scrollTo >= 0) {
schedule("afterRender", () => {
discourseDebounce(
this,
function () {
if (this.element && !this.isDestroying && !this.isDestroyed) {
$(window).scrollTop(scrollTo + 1);
}
},
0
);
});
}
},
didInsertElement() {
this._super(...arguments);
this.scrollToLastPosition();
},
_updateLastVisitedTopic(topics, order, ascending, top) {
this.set("lastVisitedTopic", null);
if (!this.highlightLastVisited) {
return;
}
if (order && order !== "activity") {
return;
}
if (top) {
return;
}
if (!topics || topics.length === 1) {
return;
}
if (ascending) {
return;
}
let user = this.currentUser;
if (!user || !user.previous_visit_at) {
return;
}
let lastVisitedTopic, topic;
let prevVisit = user.get("previousVisitAt");
// this is more efficient cause we keep appending to list
// work backwards
let start = 0;
while (topics[start] && topics[start].get("pinned")) {
start++;
}
let i;
for (i = topics.length - 1; i >= start; i--) {
if (topics[i].get("bumpedAt") > prevVisit) {
lastVisitedTopic = topics[i];
break;
}
topic = topics[i];
}
if (!lastVisitedTopic || !topic) {
return;
}
// end of list that was scanned
if (topic.get("bumpedAt") > prevVisit) {
return;
}
this.set("lastVisitedTopic", lastVisitedTopic);
},
refreshLastVisited() {
this._updateLastVisitedTopic(
this.topics,
this.order,
this.ascending,
this.top
);
},
updateAutoAddTopicsToBulkSelect(newVal) {
this.set("autoAddTopicsToBulkSelect", newVal);
},
click(e) {
let self = this;
let onClick = function (sel, callback) {
let target = $(e.target).closest(sel);
if (target.length === 1) {
callback.apply(self, [target]);
}
};
onClick("button.bulk-select", function () {
this.toggleBulkSelect();
this.rerender();
});
onClick("button.bulk-select-all", function () {
this.updateAutoAddTopicsToBulkSelect(true);
$("input.bulk-select:not(:checked)").click();
});
onClick("button.bulk-clear-all", function () {
this.updateAutoAddTopicsToBulkSelect(false);
$("input.bulk-select:checked").click();
});
onClick("th.sortable", function (e2) {
this.changeSort(e2.data("sort-order"));
this.rerender();
});
onClick("button.bulk-select-actions", function () {
const controller = showModal("topic-bulk-actions", {
model: {
topics: this.selected,
category: this.category,
},
title: "topics.bulk.actions",
});
const action = this.bulkSelectAction;
if (action) {
controller.set("refreshClosure", () => action());
}
});
},
keyDown(e) {
if (e.key === "Enter" || e.key === " ") {
let onKeyDown = (sel, callback) => {
let target = $(e.target).closest(sel);
if (target.length === 1) {
callback.apply(this, [target]);
}
};
onKeyDown("th.sortable", (e2) => {
this.changeSort(e2.data("sort-order"));
this.rerender();
});
}
},
});
\ No newline at end of file
...@@ -117,8 +117,70 @@ ...@@ -117,8 +117,70 @@
// }); // });
// Initial commit : // Initial commit :
// import Component from "@ember/component";
// import Category from "discourse/models/category";
// import discourseComputed, { observes } from "discourse-common/utils/decorators";
// import { inject as service } from "@ember/service";
// import { defaultHomepage } from "discourse/lib/utilities";
// import { and } from "@ember/object/computed";
// export default Component.extend({
// router: service(),
// tagName: "",
// didInsertElement() {
// this._super(...arguments);
// this._updateBodyClasses();
// },
// willDestroyElement() {
// this._super(...arguments);
// this._updateBodyClasses();
// },
// @observes("shouldShow")
// _updateBodyClasses() {
// const shouldCleanup = this.isDestroying || this.isDestroyed;
// if (!shouldCleanup && this.shouldShow && settings.show_as_sidebar) {
// document.body.classList.add("showcased-categories-sidebar");
// } else {
// document.body.classList.remove("showcased-categories-sidebar");
// }
// },
// get categoriesLoaded() {
// return Category.list().length !== 0;
// },
// get category1() {
// if (!this.categoriesLoaded) return false;
// return Category.findById(settings.feed_one_category);
// },
// get category2() {
// if (!this.categoriesLoaded) return false;
// return Category.findById(settings.feed_two_category);
// },
// @discourseComputed("router.currentRouteName")
// shouldShow(currentRouteName) {
// let showSidebar =
// settings.show_as_sidebar && currentRouteName === "discovery.latest";
// return currentRouteName === `discovery.${defaultHomepage()}` || showSidebar;
// },
// showTopicLists: and("shouldShow", "category1", "category2")
// });
import Component from "@ember/component"; import Component from "@ember/component";
import Category from "discourse/models/category"; import {
navigateToTopic,
showEntrance,
} from "discourse/components/topic-list-item";
import { alias, and, reads } from "@ember/object/computed";
import LoadMore from "discourse/mixins/load-more";
import discourseDebounce from "discourse-common/lib/debounce";
import { on } from "@ember/object/evented";
import { schedule } from "@ember/runloop";
import showModal from "discourse/lib/show-modal";
import discourseComputed, { observes } from "discourse-common/utils/decorators"; import discourseComputed, { observes } from "discourse-common/utils/decorators";
import { inject as service } from "@ember/service"; import { inject as service } from "@ember/service";
import { defaultHomepage } from "discourse/lib/utilities"; import { defaultHomepage } from "discourse/lib/utilities";
...@@ -136,37 +198,270 @@ export default Component.extend({ ...@@ -136,37 +198,270 @@ export default Component.extend({
this._super(...arguments); this._super(...arguments);
this._updateBodyClasses(); this._updateBodyClasses();
}, },
// export default Component.extend({
// attributeBindings: ["topic.id:data-topic-id"],
// classNameBindings: [":latest-topic-list-item", "unboundClassNames"],
@observes("shouldShow") // showEntrance,
_updateBodyClasses() { // navigateToTopic,
const shouldCleanup = this.isDestroying || this.isDestroyed;
if (!shouldCleanup && this.shouldShow && settings.show_as_sidebar) {
document.body.classList.add("showcased-categories-sidebar");
} else {
document.body.classList.remove("showcased-categories-sidebar");
}
},
get categoriesLoaded() { // click(e) {
return Category.list().length !== 0; // // for events undefined has a different meaning than false
}, // if (this.showEntrance(e) === false) {
// return false;
// }
get category1() { // return this.unhandledRowClick(e, this.topic);
if (!this.categoriesLoaded) return false; // },
return Category.findById(settings.feed_one_category);
},
get category2() { // // Can be overwritten by plugins to handle clicks on other parts of the row
if (!this.categoriesLoaded) return false; // unhandledRowClick() {},
return Category.findById(settings.feed_two_category);
},
@discourseComputed("router.currentRouteName") @discourseComputed("topic")
shouldShow(currentRouteName) { unboundClassNames(topic) {
let showSidebar = let classes = [];
settings.show_as_sidebar && currentRouteName === "discovery.latest";
return currentRouteName === `discovery.${defaultHomepage()}` || showSidebar; if (topic.get("category")) {
classes.push("category-" + topic.get("category.fullSlug"));
}
if (topic.get("tags")) {
topic.get("tags").forEach((tagName) => classes.push("tag-" + tagName));
}
["liked", "archived", "bookmarked", "pinned", "closed", "visited"].forEach(
(name) => {
if (topic.get(name)) {
classes.push(name);
}
}
);
return classes.join(" ");
}, },
showTopicLists: and("shouldShow", "category1", "category2") export default Component.extend(LoadMore, {
}); tagName: "table",
classNames: ["topic-list"],
classNameBindings: ["bulkSelectEnabled:sticky-header"],
showTopicPostBadges: true,
listTitle: "topic.title",
canDoBulkActions: and("currentUser.staff", "selected.length"),
// Overwrite this to perform client side filtering of topics, if desired
filteredTopics: alias("topics"),
_init: on("init", function () {
this.addObserver("hideCategory", this.rerender);
this.addObserver("order", this.rerender);
this.addObserver("ascending", this.rerender);
this.refreshLastVisited();
}),
@discourseComputed("bulkSelectEnabled")
toggleInTitle(bulkSelectEnabled) {
return !bulkSelectEnabled && this.canBulkSelect;
},
@discourseComputed
sortable() {
return !!this.changeSort;
},
skipHeader: reads("site.mobileView"),
@discourseComputed("order")
showLikes(order) {
return order === "likes";
},
@discourseComputed("order")
showOpLikes(order) {
return order === "op_likes";
},
@observes("topics.[]")
topicsAdded() {
// special case so we don't keep scanning huge lists
if (!this.lastVisitedTopic) {
this.refreshLastVisited();
}
},
@observes("topics", "order", "ascending", "category", "top")
lastVisitedTopicChanged() {
this.refreshLastVisited();
},
scrolled() {
this._super(...arguments);
let onScroll = this.onScroll;
if (!onScroll) {
return;
}
onScroll.call(this);
},
scrollToLastPosition() {
if (!this.scrollOnLoad) {
return;
}
let scrollTo = this.session.get("topicListScrollPosition");
if (scrollTo && scrollTo >= 0) {
schedule("afterRender", () => {
discourseDebounce(
this,
function () {
if (this.element && !this.isDestroying && !this.isDestroyed) {
$(window).scrollTop(scrollTo + 1);
}
},
0
);
});
}
},
didInsertElement() {
this._super(...arguments);
this.scrollToLastPosition();
},
_updateLastVisitedTopic(topics, order, ascending, top) {
this.set("lastVisitedTopic", null);
if (!this.highlightLastVisited) {
return;
}
if (order && order !== "activity") {
return;
}
if (top) {
return;
}
if (!topics || topics.length === 1) {
return;
}
if (ascending) {
return;
}
let user = this.currentUser;
if (!user || !user.previous_visit_at) {
return;
}
let lastVisitedTopic, topic;
let prevVisit = user.get("previousVisitAt");
// this is more efficient cause we keep appending to list
// work backwards
let start = 0;
while (topics[start] && topics[start].get("pinned")) {
start++;
}
let i;
for (i = topics.length - 1; i >= start; i--) {
if (topics[i].get("bumpedAt") > prevVisit) {
lastVisitedTopic = topics[i];
break;
}
topic = topics[i];
}
if (!lastVisitedTopic || !topic) {
return;
}
// end of list that was scanned
if (topic.get("bumpedAt") > prevVisit) {
return;
}
this.set("lastVisitedTopic", lastVisitedTopic);
},
refreshLastVisited() {
this._updateLastVisitedTopic(
this.topics,
this.order,
this.ascending,
this.top
);
},
updateAutoAddTopicsToBulkSelect(newVal) {
this.set("autoAddTopicsToBulkSelect", newVal);
},
click(e) {
let self = this;
let onClick = function (sel, callback) {
let target = $(e.target).closest(sel);
if (target.length === 1) {
callback.apply(self, [target]);
}
};
onClick("button.bulk-select", function () {
this.toggleBulkSelect();
this.rerender();
});
onClick("button.bulk-select-all", function () {
this.updateAutoAddTopicsToBulkSelect(true);
$("input.bulk-select:not(:checked)").click();
});
onClick("button.bulk-clear-all", function () {
this.updateAutoAddTopicsToBulkSelect(false);
$("input.bulk-select:checked").click();
});
onClick("th.sortable", function (e2) {
this.changeSort(e2.data("sort-order"));
this.rerender();
});
onClick("button.bulk-select-actions", function () {
const controller = showModal("topic-bulk-actions", {
model: {
topics: this.selected,
category: this.category,
},
title: "topics.bulk.actions",
});
const action = this.bulkSelectAction;
if (action) {
controller.set("refreshClosure", () => action());
}
});
},
keyDown(e) {
if (e.key === "Enter" || e.key === " ") {
let onKeyDown = (sel, callback) => {
let target = $(e.target).closest(sel);
if (target.length === 1) {
callback.apply(this, [target]);
}
};
onKeyDown("th.sortable", (e2) => {
this.changeSort(e2.data("sort-order"));
this.rerender();
});
}
},
});
\ No newline at end of file
...@@ -37,10 +37,10 @@ ...@@ -37,10 +37,10 @@
# - "above-main-container" # - "above-main-container"
# - "below-site-header" # - "below-site-header"
# description: "Advanced setting for additional customization" # description: "Advanced setting for additional customization"
# ///////////////////////////////////////////////////// # /////////////////////////////////////////////////////
# ///////////////////////////////////////////////////// # /////////////////////////////////////////////////////
# ///////////////////////////////////////////////////// # /////////////////////////////////////////////////////
show_as_sidebar: show_as_sidebar:
type: bool type: bool
default: false default: false
description: "If enabled, the showcased categories will only be rendered in a sidebar on the latest page." description: "If enabled, the showcased categories will only be rendered in a sidebar on the latest page."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment