userAvatar.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. return Avatars.find({ userId: Meteor.userId() }).each();
  147. },
  148. isSelected() {
  149. const userProfile = ReactiveCache.getCurrentUser().profile;
  150. const avatarUrl = userProfile && userProfile.avatarUrl;
  151. const currentAvatarUrl = `${this.currentData().link()}?auth=false&brokenIsFine=true`;
  152. return avatarUrl === currentAvatarUrl;
  153. },
  154. noAvatarUrl() {
  155. const userProfile = ReactiveCache.getCurrentUser().profile;
  156. const avatarUrl = userProfile && userProfile.avatarUrl;
  157. return !avatarUrl;
  158. },
  159. setAvatar(avatarUrl) {
  160. ReactiveCache.getCurrentUser().setAvatarUrl(avatarUrl);
  161. },
  162. setError(error) {
  163. this.error.set(error);
  164. },
  165. events() {
  166. return [
  167. {
  168. 'click .js-upload-avatar'() {
  169. this.$('.js-upload-avatar-input').click();
  170. },
  171. 'change .js-upload-avatar-input'(event) {
  172. const self = this;
  173. if (event.currentTarget.files && event.currentTarget.files[0]) {
  174. const uploader = Avatars.insert(
  175. {
  176. file: event.currentTarget.files[0],
  177. chunkSize: 'dynamic',
  178. },
  179. false,
  180. );
  181. uploader.on('error', (error, fileData) => {
  182. self.setError(error.reason);
  183. });
  184. uploader.start();
  185. }
  186. },
  187. 'click .js-select-avatar'() {
  188. const avatarUrl = `${this.currentData().link()}?auth=false&brokenIsFine=true`;
  189. this.setAvatar(avatarUrl);
  190. },
  191. 'click .js-select-initials'() {
  192. this.setAvatar('');
  193. },
  194. 'click .js-delete-avatar'(event) {
  195. Avatars.remove(this.currentData()._id);
  196. event.stopPropagation();
  197. },
  198. },
  199. ];
  200. },
  201. }).register('changeAvatarPopup');
  202. Template.cardMembersPopup.helpers({
  203. isCardMember() {
  204. const card = Template.parentData();
  205. const cardMembers = card.getMembers();
  206. return _.contains(cardMembers, this.userId);
  207. },
  208. user() {
  209. return ReactiveCache.getUser(this.userId);
  210. },
  211. });
  212. Template.cardMembersPopup.events({
  213. 'click .js-select-member'(event) {
  214. const card = Utils.getCurrentCard();
  215. const memberId = this.userId;
  216. card.toggleMember(memberId);
  217. event.preventDefault();
  218. },
  219. });
  220. Template.cardMemberPopup.helpers({
  221. user() {
  222. return ReactiveCache.getUser(this.userId);
  223. },
  224. });
  225. Template.cardMemberPopup.events({
  226. 'click .js-remove-member'() {
  227. ReactiveCache.getCard(this.cardId).unassignMember(this.userId);
  228. Popup.back();
  229. },
  230. 'click .js-edit-profile': Popup.open('editProfile'),
  231. });