userAvatar.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. import Cards from '/models/cards';
  2. import Avatars from '/models/avatars';
  3. import Users from '/models/users';
  4. import Org from '/models/org';
  5. import Team from '/models/team';
  6. import { formatFleURL } from 'meteor/ostrio:files/lib';
  7. Template.userAvatar.helpers({
  8. userData() {
  9. // We need to handle a special case for the search results provided by the
  10. // `matteodem:easy-search` package. Since these results gets published in a
  11. // separate collection, and not in the standard Meteor.Users collection as
  12. // expected, we use a component parameter ("property") to distinguish the
  13. // two cases.
  14. const userCollection = this.esSearch ? ESSearchResults : Users;
  15. return userCollection.findOne(this.userId, {
  16. fields: {
  17. profile: 1,
  18. username: 1,
  19. },
  20. });
  21. },
  22. memberType() {
  23. const user = Users.findOne(this.userId);
  24. return user && user.isBoardAdmin() ? 'admin' : 'normal';
  25. },
  26. /*
  27. presenceStatusClassName() {
  28. const user = Users.findOne(this.userId);
  29. const userPresence = presences.findOne({ userId: this.userId });
  30. if (user && user.isInvitedTo(Session.get('currentBoard'))) return 'pending';
  31. else if (!userPresence) return 'disconnected';
  32. else if (Session.equals('currentBoard', userPresence.state.currentBoardId))
  33. return 'active';
  34. else return 'idle';
  35. },
  36. */
  37. });
  38. Template.userAvatarInitials.helpers({
  39. initials() {
  40. const user = Users.findOne(this.userId);
  41. return user && user.getInitials();
  42. },
  43. viewPortWidth() {
  44. const user = Users.findOne(this.userId);
  45. return ((user && user.getInitials().length) || 1) * 12;
  46. },
  47. });
  48. BlazeComponent.extendComponent({
  49. onCreated() {
  50. this.error = new ReactiveVar('');
  51. this.loading = new ReactiveVar(false);
  52. this.findOrgsOptions = new ReactiveVar({});
  53. this.page = new ReactiveVar(1);
  54. this.autorun(() => {
  55. const limitOrgs = this.page.get() * Number.MAX_SAFE_INTEGER;
  56. this.subscribe('org', this.findOrgsOptions.get(), limitOrgs, () => {});
  57. });
  58. },
  59. onRendered() {
  60. this.setLoading(false);
  61. },
  62. setError(error) {
  63. this.error.set(error);
  64. },
  65. setLoading(w) {
  66. this.loading.set(w);
  67. },
  68. isLoading() {
  69. return this.loading.get();
  70. },
  71. events() {
  72. return [
  73. {
  74. 'keyup input'() {
  75. this.setError('');
  76. },
  77. 'click .js-manage-board-removeOrg': Popup.open('removeBoardOrg'),
  78. },
  79. ];
  80. },
  81. }).register('boardOrgRow');
  82. Template.boardOrgRow.helpers({
  83. orgData() {
  84. const orgCollection = this.esSearch ? ESSearchResults : Org;
  85. return orgCollection.findOne(this.orgId);
  86. },
  87. currentUser(){
  88. return Meteor.user();
  89. },
  90. });
  91. Template.boardOrgName.helpers({
  92. orgName() {
  93. const org = Org.findOne(this.orgId);
  94. return org && org.orgDisplayName;
  95. },
  96. orgViewPortWidth() {
  97. const org = Org.findOne(this.orgId);
  98. return ((org && org.orgDisplayName.length) || 1) * 12;
  99. },
  100. });
  101. BlazeComponent.extendComponent({
  102. onCreated() {
  103. this.error = new ReactiveVar('');
  104. this.loading = new ReactiveVar(false);
  105. this.findOrgsOptions = new ReactiveVar({});
  106. this.page = new ReactiveVar(1);
  107. this.autorun(() => {
  108. const limitTeams = this.page.get() * Number.MAX_SAFE_INTEGER;
  109. this.subscribe('team', this.findOrgsOptions.get(), limitTeams, () => {});
  110. });
  111. },
  112. onRendered() {
  113. this.setLoading(false);
  114. },
  115. setError(error) {
  116. this.error.set(error);
  117. },
  118. setLoading(w) {
  119. this.loading.set(w);
  120. },
  121. isLoading() {
  122. return this.loading.get();
  123. },
  124. events() {
  125. return [
  126. {
  127. 'keyup input'() {
  128. this.setError('');
  129. },
  130. 'click .js-manage-board-removeTeam': Popup.open('removeBoardTeam'),
  131. },
  132. ];
  133. },
  134. }).register('boardTeamRow');
  135. Template.boardTeamRow.helpers({
  136. teamData() {
  137. const teamCollection = this.esSearch ? ESSearchResults : Team;
  138. return teamCollection.findOne(this.teamId);
  139. },
  140. currentUser(){
  141. return Meteor.user();
  142. },
  143. });
  144. Template.boardTeamName.helpers({
  145. teamName() {
  146. const team = Team.findOne(this.teamId);
  147. return team && team.teamDisplayName;
  148. },
  149. teamViewPortWidth() {
  150. const team = Team.findOne(this.teamId);
  151. return ((team && team.teamDisplayName.length) || 1) * 12;
  152. },
  153. });
  154. BlazeComponent.extendComponent({
  155. onCreated() {
  156. this.error = new ReactiveVar('');
  157. Meteor.subscribe('my-avatars');
  158. },
  159. uploadedAvatars() {
  160. return Avatars.find({ userId: Meteor.userId() }).each();
  161. },
  162. isSelected() {
  163. const userProfile = Meteor.user().profile;
  164. const avatarUrl = userProfile && userProfile.avatarUrl;
  165. const currentAvatarUrl = `${this.currentData().link()}?auth=false&brokenIsFine=true`;
  166. return avatarUrl === currentAvatarUrl;
  167. },
  168. noAvatarUrl() {
  169. const userProfile = Meteor.user().profile;
  170. const avatarUrl = userProfile && userProfile.avatarUrl;
  171. return !avatarUrl;
  172. },
  173. setAvatar(avatarUrl) {
  174. Meteor.user().setAvatarUrl(avatarUrl);
  175. },
  176. setError(error) {
  177. this.error.set(error);
  178. },
  179. events() {
  180. return [
  181. {
  182. 'click .js-upload-avatar'() {
  183. this.$('.js-upload-avatar-input').click();
  184. },
  185. 'change .js-upload-avatar-input'(event) {
  186. const self = this;
  187. if (event.currentTarget.files && event.currentTarget.files[0]) {
  188. const uploader = Avatars.insert(
  189. {
  190. file: event.currentTarget.files[0],
  191. chunkSize: 'dynamic',
  192. },
  193. false,
  194. );
  195. uploader.on('uploaded', (error, fileRef) => {
  196. if (!error) {
  197. self.setAvatar(
  198. `${formatFleURL(fileRef)}?auth=false&brokenIsFine=true`,
  199. );
  200. }
  201. });
  202. uploader.on('error', (error, fileData) => {
  203. self.setError(error.reason);
  204. });
  205. uploader.start();
  206. }
  207. },
  208. 'click .js-select-avatar'() {
  209. const avatarUrl = `${this.currentData().link()}?auth=false&brokenIsFine=true`;
  210. this.setAvatar(avatarUrl);
  211. },
  212. 'click .js-select-initials'() {
  213. this.setAvatar('');
  214. },
  215. 'click .js-delete-avatar'() {
  216. Avatars.remove(this.currentData()._id);
  217. },
  218. },
  219. ];
  220. },
  221. }).register('changeAvatarPopup');
  222. Template.cardMembersPopup.helpers({
  223. isCardMember() {
  224. const card = Template.parentData();
  225. const cardMembers = card.getMembers();
  226. return _.contains(cardMembers, this.userId);
  227. },
  228. user() {
  229. return Users.findOne(this.userId);
  230. },
  231. });
  232. Template.cardMembersPopup.events({
  233. 'click .js-select-member'(event) {
  234. const card = Utils.getCurrentCard();
  235. const memberId = this.userId;
  236. card.toggleMember(memberId);
  237. event.preventDefault();
  238. },
  239. });
  240. Template.cardMemberPopup.helpers({
  241. user() {
  242. return Users.findOne(this.userId);
  243. },
  244. });
  245. Template.cardMemberPopup.events({
  246. 'click .js-remove-member'() {
  247. Cards.findOne(this.cardId).unassignMember(this.userId);
  248. Popup.back();
  249. },
  250. 'click .js-edit-profile': Popup.open('editProfile'),
  251. });