userAvatar.js 6.3 KB

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