Skip to content

Commit

Permalink
Merge pull request #480 from crossroads/master
Browse files Browse the repository at this point in the history
[Release] Admin v0.17.9
  • Loading branch information
abulsayyad123 authored Dec 30, 2020
2 parents ce496d1 + 5af9f82 commit e19e28f
Show file tree
Hide file tree
Showing 49 changed files with 1,457 additions and 92 deletions.
32 changes: 32 additions & 0 deletions app/adapters/shareable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Ember from "ember";
import DS from "ember-data";
import config from "../config/environment";

export default DS.JSONAPIAdapter.extend({
namespace: config.APP.NAMESPACE_V2,
host: config.APP.API_HOST_URL,
session: Ember.inject.service(),

headers: Ember.computed("session.authToken", function() {
return {
Authorization: `Bearer ${this.get("session.authToken")}`,
"Accept-Language": this.get("session.language"),
"X-GOODCITY-APP-NAME": config.APP.NAME,
"X-GOODCITY-APP-VERSION": config.APP.VERSION,
"X-GOODCITY-APP-SHA": config.APP.SHA,
"X-GOODCITY-APP-SHARED-SHA": config.APP.SHARED_SHA
};
}),

updateRecord(store, type, snapshot) {
var data = {};
var serializer = store.serializerFor(type.modelName);

serializer.serializeIntoHash(data, type, snapshot, { includeId: true });

var id = snapshot.id;
var url = this.buildURL(type.modelName, id, snapshot, "updateRecord");

return this.ajax(url, "PUT", { data });
}
});
51 changes: 40 additions & 11 deletions app/controllers/message_base_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,40 @@ export default Ember.Controller.extend({
return this.store.peekAll("message");
}),

messages: Ember.computed("allMessages.[]", "offer", "item", function() {
var messages = this.get("allMessages");
messages = this.get("isItemThread")
? messages.filterBy("itemId", this.get("item.id"))
: messages
.filterBy("offerId", this.get("offer.id"))
.filterBy("item", null);
return messages.filter(m => {
return Boolean(m.get("isPrivate")) === this.get("isPrivate");
});
}),
messages: Ember.computed(
"allMessages.[]",
"[email protected]",
"offer",
"item",
"isPrivate",
"recipientId",
function() {
var messages = this.get("allMessages");
messages = this.get("isItemThread")
? messages.filterBy("itemId", this.get("item.id"))
: messages
.filterBy("offerId", this.get("offer.id"))
.filterBy("item", null);

// For a public chat with no recipient, we default to the donor
let recipientId =
this.get("recipientId") ||
(this.get("isPrivate") ? null : this.get("offer.createdById"));

if (recipientId) {
messages = messages.filter(m => {
return (
m.get("recipientId") === recipientId ||
m.get("senderId") === recipientId
);
});
}

return messages.filter(m => {
return Boolean(m.get("isPrivate")) === this.get("isPrivate");
});
}
),

messagesAndVersions: Ember.computed(
"messages.[]",
Expand Down Expand Up @@ -163,6 +186,12 @@ export default Ember.Controller.extend({
"user",
this.get("session.currentUser.id")
);

if (!this.get("isPrivate")) {
values.recipientId =
this.get("recipientId") || this.get("offer.createdById");
}

this.get("messageLinkConvertor").convert(values);
var message = this.store.createRecord("message", values);
message
Expand Down
79 changes: 62 additions & 17 deletions app/controllers/my_notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import AjaxPromise from "goodcity/utils/ajax-promise";

const { computed } = Ember;

const MSG_KEY = msg => {
return [
msg.get("isPrivate") ? "private" : "public",
msg.get("messageableType") || "-",
msg.get("messageableId") || "-"
].join("/");
};

export default Ember.Controller.extend({
messagesUtil: Ember.inject.service("messages"),
subscriptions: Ember.inject.controller(),
Expand Down Expand Up @@ -50,7 +42,7 @@ export default Ember.Controller.extend({
return;
}

let notif = notifications.findBy("key", MSG_KEY(msg));
let notif = notifications.findBy("key", this.buildMessageKey(msg));

if (notif) {
// Update existing one
Expand Down Expand Up @@ -97,14 +89,19 @@ export default Ember.Controller.extend({
this.get("store").findRecord("offer", recordId);
}

let controller = this;
let notification = Ember.Object.create(lastMessage.getProperties(props));
notification.setProperties({
key: MSG_KEY(lastMessage),
key: this.buildMessageKey(lastMessage),
item: item,
messages: messages,
isSingleMessage: computed.equal("unreadCount", 1),
isThread: computed.not("isSingleMessage"),
offer: offer,
recipientId: this.getRecipientId(lastMessage),
isCharity: computed("offer.createdById", function() {
return controller.isCharityDiscussion(this.get("messages.lastObject"));
}),
text: computed("messages.[]", function() {
return this.get("messages")
.sortBy("id")
Expand Down Expand Up @@ -134,7 +131,7 @@ export default Ember.Controller.extend({
});

return _.chain(groupedMessages)
.groupBy(MSG_KEY)
.groupBy(m => this.buildMessageKey(m))
.map(msgs => this.messagesToNotification(msgs))
.value();
},
Expand All @@ -152,6 +149,45 @@ export default Ember.Controller.extend({
});
},

buildMessageKey(msg) {
return [
msg.get("isPrivate") ? "private" : "public",
msg.get("messageableType") || "-",
msg.get("messageableId") || "-",
this.getRecipientId(msg) || "-"
].join("/");
},

getRecipientId(msg) {
if (msg.get("isPrivate")) {
return null;
}

if (msg.get("recipientId")) {
// Case: staff is sending the message
return msg.get("recipientId");
}

// Case: user is sending the message
return msg.get("senderId");
},

isCharityDiscussion(message) {
if (
message.get("messageableType") !== "Offer" ||
message.get("isPrivate")
) {
return false;
}

const donorId = message.get("offer.createdById");

return (
message.get("senderId") !== donorId &&
message.get("recipientId") !== donorId
);
},

actions: {
/**
* Loads a page of Message Notifications
Expand All @@ -178,7 +214,7 @@ export default Ember.Controller.extend({
.then(data => this.toMessageModels(data))
.then(messages => {
const notifications = _.chain(messages)
.groupBy(MSG_KEY)
.groupBy(m => this.buildMessageKey(m))
.map(o => this.buildNotifications(o))
.flatten()
.value();
Expand All @@ -188,10 +224,19 @@ export default Ember.Controller.extend({
});
},

view(messageId) {
var message = this.store.peekRecord("message", messageId);
var route = this.get("messagesUtil").getRoute(message);
this.transitionToRoute.apply(this, route);
view(notification) {
if (notification.get("isCharity")) {
this.transitionToRoute(
"review_offer.share.chat",
notification.get("offer.id"),
notification.get("recipientId")
);
} else {
const messageId = notification.get("id");
var message = this.store.peekRecord("message", messageId);
var route = this.get("messagesUtil").getRoute(message);
this.transitionToRoute.apply(this, route);
}
},

markThreadRead(notification) {
Expand All @@ -200,7 +245,7 @@ export default Ember.Controller.extend({
this.get("messagesUtil").markRead(message);
notification.set("unreadCount", 0);
} else {
this.send("view", notification.id);
this.send("view", notification);
}
},

Expand Down
11 changes: 7 additions & 4 deletions app/controllers/review_item/accept.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ export default Ember.Controller.extend({
),

itemType: Ember.computed("itemTypeId", function() {
return this.get("store").peekRecord(
"packageType",
this.get("itemTypeId.id") || this.get("itemTypeId")
);
const typeId = this.get("itemTypeId.id") || this.get("itemTypeId");

if (!typeId) {
return null;
}

return this.get("store").peekRecord("packageType", typeId);
}),

subPackageTypes: Ember.computed("itemType", function() {
Expand Down
39 changes: 39 additions & 0 deletions app/controllers/review_offer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,45 @@ export default Ember.Controller.extend(AsyncTasksMixin, {
displayCompleteReviewPopup: false,
displayCompleteReceivePopup: false,

allShareables: Ember.computed(function() {
return this.get("store").peekAll("shareable");
}),

allMessages: Ember.computed(function() {
return this.get("store").peekAll("message");
}),

offerShareable: Ember.computed(
"offer.id",
"allShareables.length",
"allShareables.[]",
"allShareables.@each.{id,active,publicUid}",
function() {
return this.get("allShareables").find(sh => {
return (
sh.get("resourceType") == "Offer" &&
sh.get("resourceId") == this.get("offer.id") &&
sh.get("active")
);
});
}
),

unreadCharityMessages: Ember.computed(
"offer.id",
"allMessages.[]",
"allMessages.length",
"[email protected]",
function() {
return this.get("allMessages")
.filterBy("isCharityConversation")
.filterBy("isUnread")
.filterBy("offerId", this.get("offer.id"));
}
),

isShared: Ember.computed.alias("offerShareable"),

displayOfferOptions: Ember.computed({
get: function() {
return false;
Expand Down
22 changes: 22 additions & 0 deletions app/controllers/review_offer/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@ export default Ember.Controller.extend({
offer: Ember.computed.alias("model"),
reviewOffer: Ember.inject.controller(),

lastMessage: Ember.computed(
"offer.messages",
"offer.messages.[]",
function() {
return this.get("offer.messages")
.filter(m => !m.get("isCharityConversation"))
.sortBy("createdAt")
.get("lastObject");
}
),

unreadOfferMessagesCount: Ember.computed(
"offer.messages",
"offer.messages.[]",
function() {
return this.get("offer.messages")
.filter(m => !m.get("isCharityConversation"))
.filterBy("isUnread")
.get("length");
}
),

offerAndItems: Ember.computed("[email protected]", function() {
// avoid deleted-items which are not persisted yet.
var elements = this.get("items")
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/review_offer/share.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Ember from "ember";
import AsyncTasksMixin from "../../mixins/async_tasks";

export default Ember.Controller.extend(AsyncTasksMixin, {
store: Ember.inject.service(),
offerService: Ember.inject.service(),
parentController: Ember.inject.controller("review_offer"),
offer: Ember.computed.alias("parentController.offer"),
isShared: Ember.computed.alias("parentController.isShared"),
offerShareable: Ember.computed.alias("parentController.offerShareable")
});
11 changes: 11 additions & 0 deletions app/controllers/review_offer/share/chat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import MessagesBaseController from "goodcity/controllers/message_base_controller";

export default MessagesBaseController.extend({
displayCannedMessages: true,

actions: {
leave() {
this.replaceRoute("review_offer.share");
}
}
});
Loading

0 comments on commit e19e28f

Please sign in to comment.