DEV: Ember 3.8.0

Co-Authored-By: majakomel <maja.komel@gmail.com>
This commit is contained in:
Maja Komel
2019-04-26 12:16:21 +02:00
committed by Joffrey JAFFEUX
parent c617e512ad
commit 4b455e741e
63 changed files with 573 additions and 438 deletions
@@ -3,9 +3,7 @@ import RestModel from "discourse/models/rest";
import { popupAjaxError } from "discourse/lib/ajax-error";
export default RestModel.extend({
canToggle: function() {
return this.get("can_undo") || this.get("can_act");
}.property("can_undo", "can_act"),
canToggle: Ember.computed.or("can_undo", "can_act"),
// Remove it
removeAction: function() {
@@ -1,13 +1,15 @@
import { ajax } from "discourse/lib/ajax";
import BadgeGrouping from "discourse/models/badge-grouping";
import RestModel from "discourse/models/rest";
import computed from "ember-addons/ember-computed-decorators";
const Badge = RestModel.extend({
newBadge: Ember.computed.none("id"),
url: function() {
@computed
url() {
return Discourse.getURL(`/badges/${this.get("id")}/${this.get("slug")}`);
}.property(),
},
/**
Update this badge with the response returned by the server on save.
@@ -31,10 +33,11 @@ const Badge = RestModel.extend({
}
},
badgeTypeClassName: function() {
const type = this.get("badge_type.name") || "";
@computed("badge_type.name")
badgeTypeClassName(type) {
type = type || "";
return "badge-type-" + type.toLowerCase();
}.property("badge_type.name"),
},
/**
Save and update the badge from the server's response.
@@ -77,9 +77,10 @@ const Composer = RestModel.extend({
draftSaving: false,
draftSaved: false,
archetypes: function() {
@computed
archetypes() {
return this.site.get("archetypes");
}.property(),
},
@computed("action")
sharedDraft: action => action === CREATE_SHARED_DRAFT,
@@ -184,9 +185,10 @@ const Composer = RestModel.extend({
.property()
.volatile(),
archetype: function() {
return this.get("archetypes").findBy("id", this.get("archetypeId"));
}.property("archetypeId"),
@computed("archetypeId")
archetype(archetypeId) {
return this.get("archetypes").findBy("id", archetypeId);
},
archetypeChanged: function() {
return this.set("metaData", Ember.Object.create());
@@ -377,30 +379,27 @@ const Composer = RestModel.extend({
);
},
titleLengthValid: function() {
if (
this.user.get("admin") &&
this.get("post.static_doc") &&
this.get("titleLength") > 0
)
return true;
if (this.get("titleLength") < this.get("minimumTitleLength")) return false;
return this.get("titleLength") <= this.siteSettings.max_topic_title_length;
}.property("minimumTitleLength", "titleLength", "post.static_doc"),
@computed("minimumTitleLength", "titleLength", "post.static_doc")
titleLengthValid(minTitleLength, titleLength, staticDoc) {
if (this.user.get("admin") && staticDoc && titleLength > 0) return true;
if (titleLength < minTitleLength) return false;
return titleLength <= this.siteSettings.max_topic_title_length;
},
hasMetaData: function() {
const metaData = this.get("metaData");
@computed("metaData")
hasMetaData(metaData) {
return metaData ? Ember.isEmpty(Ember.keys(this.get("metaData"))) : false;
}.property("metaData"),
},
/**
Did the user make changes to the reply?
@property replyDirty
**/
replyDirty: function() {
return this.get("reply") !== this.get("originalText");
}.property("reply", "originalText"),
@computed("reply", "originalText")
replyDirty(reply, originalText) {
return reply !== originalText;
},
/**
Did the user make changes to the topic title?
@@ -417,9 +416,10 @@ const Composer = RestModel.extend({
@property missingTitleCharacters
**/
missingTitleCharacters: function() {
return this.get("minimumTitleLength") - this.get("titleLength");
}.property("minimumTitleLength", "titleLength"),
@computed("minimumTitleLength", "titleLength")
missingTitleCharacters(minimumTitleLength, titleLength) {
return minimumTitleLength - titleLength;
},
/**
Minimum number of characters for a title to be valid.
@@ -474,23 +474,25 @@ const Composer = RestModel.extend({
@property titleLength
**/
titleLength: function() {
const title = this.get("title") || "";
@computed("title")
titleLength(title) {
title = title || "";
return title.replace(/\s+/gim, " ").trim().length;
}.property("title"),
},
/**
Computes the length of the reply minus the quote(s) and non-significant whitespaces
@property replyLength
**/
replyLength: function() {
let reply = this.get("reply") || "";
@computed("reply")
replyLength(reply) {
reply = reply || "";
while (Quote.REGEXP.test(reply)) {
reply = reply.replace(Quote.REGEXP, "");
}
return reply.replace(/\s+/gim, " ").trim().length;
}.property("reply"),
},
_setupComposer: function() {
this.set("archetypeId", this.site.get("default_archetype"));
@@ -1,8 +1,11 @@
import computed from "ember-addons/ember-computed-decorators";
const PermissionType = Discourse.Model.extend({
description: function() {
@computed("id")
description(id) {
var key = "";
switch (this.get("id")) {
switch (id) {
case 1:
key = "full";
break;
@@ -14,7 +17,7 @@ const PermissionType = Discourse.Model.extend({
break;
}
return I18n.t("permission_types." + key);
}.property("id")
}
});
PermissionType.FULL = 1;
@@ -17,16 +17,17 @@ const Post = RestModel.extend({
return Discourse.SiteSettings;
},
shareUrl: function() {
@computed("url")
shareUrl(url) {
const user = Discourse.User.current();
const userSuffix = user ? "?u=" + user.get("username_lower") : "";
if (this.get("firstPost")) {
return this.get("topic.url") + userSuffix;
} else {
return this.get("url") + userSuffix;
return url + userSuffix;
}
}.property("url"),
},
new_user: Ember.computed.equal("trust_level", 0),
firstPost: Ember.computed.equal("post_number", 1),
@@ -36,36 +37,31 @@ const Post = RestModel.extend({
deleted: Ember.computed.or("deleted_at", "deletedViaTopic"),
notDeleted: Ember.computed.not("deleted"),
showName: function() {
const name = this.get("name");
@computed("name", "username")
showName(name, username) {
return (
name &&
name !== this.get("username") &&
Discourse.SiteSettings.display_name_on_posts
name && name !== username && Discourse.SiteSettings.display_name_on_posts
);
}.property("name", "username"),
},
postDeletedBy: function() {
if (this.get("firstPost")) {
return this.get("topic.deleted_by");
}
return this.get("deleted_by");
}.property("firstPost", "deleted_by", "topic.deleted_by"),
@computed("firstPost", "deleted_by", "topic.deleted_by")
postDeletedBy(firstPost, deletedBy, topicDeletedBy) {
return firstPost ? topicDeletedBy : deletedBy;
},
postDeletedAt: function() {
if (this.get("firstPost")) {
return this.get("topic.deleted_at");
}
return this.get("deleted_at");
}.property("firstPost", "deleted_at", "topic.deleted_at"),
@computed("firstPost", "deleted_at", "topic.deleted_at")
postDeletedAt(firstPost, deletedAt, topicDeletedAt) {
return firstPost ? topicDeletedAt : deletedAt;
},
url: function() {
@computed("post_number", "topic_id", "topic.slug")
url(postNr, topicId, slug) {
return postUrl(
this.get("topic.slug") || this.get("topic_slug"),
this.get("topic_id") || this.get("topic.id"),
this.get("post_number")
slug || this.get("topic_slug"),
topicId || this.get("topic.id"),
postNr
);
}.property("post_number", "topic_id", "topic.slug"),
},
// Don't drop the /1
@computed("post_number", "url")
@@ -1,3 +1,5 @@
import computed from "ember-addons/ember-computed-decorators";
export default Ember.ArrayProxy.extend({
loading: false,
loadingMore: false,
@@ -12,9 +14,10 @@ export default Ember.ArrayProxy.extend({
__type: null,
resultSetMeta: null,
canLoadMore: function() {
return this.get("length") < this.get("totalRows");
}.property("totalRows", "length"),
@computed("totalRows", "length")
canLoadMore(totalRows, length) {
return length < totalRows;
},
loadMore() {
const loadMoreUrl = this.get("loadMoreUrl");
@@ -1,4 +1,6 @@
import { ajax } from "discourse/lib/ajax";
import computed from "ember-addons/ember-computed-decorators";
/**
A model representing a Topic's details that aren't always present, such as a list of participants.
When showing topics in lists and such this information should not be required.
@@ -29,15 +31,15 @@ const TopicDetails = RestModel.extend({
this.set("loaded", true);
},
notificationReasonText: function() {
let level = this.get("notification_level");
@computed("notification_level", "notifications_reason_id")
notificationReasonText(level, reason) {
if (typeof level !== "number") {
level = 1;
}
let localeString = `topic.notifications.reasons.${level}`;
if (typeof this.get("notifications_reason_id") === "number") {
const tmp = localeString + "_" + this.get("notifications_reason_id");
if (typeof reason === "number") {
const tmp = localeString + "_" + reason;
// some sane protection for missing translations of edge cases
if (I18n.lookup(tmp)) {
localeString = tmp;
@@ -55,7 +57,7 @@ const TopicDetails = RestModel.extend({
basePath: Discourse.BaseUri
});
}
}.property("notification_level", "notifications_reason_id"),
},
updateNotifications(v) {
this.set("notification_level", v);
@@ -1,23 +1,24 @@
import RestModel from "discourse/models/rest";
import UserAction from "discourse/models/user-action";
import { i18n } from "discourse/lib/computed";
import computed from "ember-addons/ember-computed-decorators";
export default RestModel.extend({
isPM: function() {
const actionType = this.get("action_type");
@computed("action_type")
isPM(actionType) {
return (
actionType === UserAction.TYPES.messages_sent ||
actionType === UserAction.TYPES.messages_received
);
}.property("action_type"),
},
description: i18n("action_type", "user_action_groups.%@"),
isResponse: function() {
const actionType = this.get("action_type");
@computed("action_type")
isResponse(actionType) {
return (
actionType === UserAction.TYPES.replies ||
actionType === UserAction.TYPES.quotes
);
}.property("action_type")
}
});
@@ -164,16 +164,7 @@ const UserAction = RestModel.extend({
}
},
children: function() {
const g = this.get("childGroups");
let rval = [];
if (g) {
rval = [g.likes, g.stars, g.edits, g.bookmarks].filter(function(i) {
return i.get("items") && i.get("items").length > 0;
});
}
return rval;
}.property(
@computed(
"childGroups",
"childGroups.likes.items",
"childGroups.likes.items.[]",
@@ -183,7 +174,17 @@ const UserAction = RestModel.extend({
"childGroups.edits.items.[]",
"childGroups.bookmarks.items",
"childGroups.bookmarks.items.[]"
),
)
children() {
const g = this.get("childGroups");
let rval = [];
if (g) {
rval = [g.likes, g.stars, g.edits, g.bookmarks].filter(function(i) {
return i.get("items") && i.get("items").length > 0;
});
}
return rval;
},
switchToActing() {
this.setProperties({
@@ -1,12 +1,14 @@
import { ajax } from "discourse/lib/ajax";
import Badge from "discourse/models/badge";
import computed from "ember-addons/ember-computed-decorators";
const UserBadge = Discourse.Model.extend({
@computed
postUrl: function() {
if (this.get("topic_title")) {
return "/t/-/" + this.get("topic_id") + "/" + this.get("post_number");
}
}.property(), // avoid the extra bindings for now
}, // avoid the extra bindings for now
revoke() {
return ajax("/user_badges/" + this.get("id"), {
@@ -3,6 +3,7 @@ import { url } from "discourse/lib/computed";
import RestModel from "discourse/models/rest";
import UserAction from "discourse/models/user-action";
import { emojiUnescape } from "discourse/lib/text";
import computed from "ember-addons/ember-computed-decorators";
export default RestModel.extend({
loaded: false,
@@ -11,8 +12,8 @@ export default RestModel.extend({
this.setProperties({ itemsLoaded: 0, content: [] });
}.on("init"),
filterParam: function() {
const filter = this.get("filter");
@computed("filter")
filterParam(filter) {
if (filter === Discourse.UserAction.TYPES.replies) {
return [UserAction.TYPES.replies, UserAction.TYPES.quotes].join(",");
}
@@ -22,7 +23,7 @@ export default RestModel.extend({
}
return filter;
}.property("filter"),
},
baseUrl: url(
"itemsLoaded",
@@ -45,9 +46,10 @@ export default RestModel.extend({
return this.findItems();
},
noContent: function() {
@computed("loaded", "content.[]")
noContent() {
return this.get("loaded") && this.get("content").length === 0;
}.property("loaded", "content.[]"),
},
remove(userAction) {
// 1) remove the user action from the child groups