userAvatar.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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 Users.findOne(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 Org.findOne(this.orgId);
  79. },
  80. currentUser(){
  81. return Meteor.user();
  82. },
  83. });
  84. Template.boardOrgName.helpers({
  85. orgName() {
  86. const org = Org.findOne(this.orgId);
  87. return org && org.orgDisplayName;
  88. },
  89. orgViewPortWidth() {
  90. const org = Org.findOne(this.orgId);
  91. return ((org && org.orgDisplayName.length) || 1) * 12;
  92. },
  93. });
  94. BlazeComponent.extendComponent({
  95. onCreated() {
  96. this.error = new ReactiveVar('');
  97. this.loading = new ReactiveVar(false);
  98. this.findOrgsOptions = new ReactiveVar({});
  99. this.page = new ReactiveVar(1);
  100. this.autorun(() => {
  101. const limitTeams = this.page.get() * Number.MAX_SAFE_INTEGER;
  102. this.subscribe('team', this.findOrgsOptions.get(), limitTeams, () => {});
  103. });
  104. },
  105. onRendered() {
  106. this.setLoading(false);
  107. },
  108. setError(error) {
  109. this.error.set(error);
  110. },
  111. setLoading(w) {
  112. this.loading.set(w);
  113. },
  114. isLoading() {
  115. return this.loading.get();
  116. },
  117. events() {
  118. return [
  119. {
  120. 'keyup input'() {
  121. this.setError('');
  122. },
  123. 'click .js-manage-board-removeTeam': Popup.open('removeBoardTeam'),
  124. },
  125. ];
  126. },
  127. }).register('boardTeamRow');
  128. Template.boardTeamRow.helpers({
  129. teamData() {
  130. return Team.findOne(this.teamId);
  131. },
  132. currentUser(){
  133. return Meteor.user();
  134. },
  135. });
  136. Template.boardTeamName.helpers({
  137. teamName() {
  138. const team = Team.findOne(this.teamId);
  139. return team && team.teamDisplayName;
  140. },
  141. teamViewPortWidth() {
  142. const team = Team.findOne(this.teamId);
  143. return ((team && team.teamDisplayName.length) || 1) * 12;
  144. },
  145. });
  146. BlazeComponent.extendComponent({
  147. onCreated() {
  148. this.error = new ReactiveVar('');
  149. Meteor.subscribe('my-avatars');
  150. },
  151. uploadedAvatars() {
  152. return Avatars.find({ userId: Meteor.userId() }).each();
  153. },
  154. isSelected() {
  155. const userProfile = Meteor.user().profile;
  156. const avatarUrl = userProfile && userProfile.avatarUrl;
  157. const currentAvatarUrl = `${this.currentData().link()}?auth=false&brokenIsFine=true`;
  158. return avatarUrl === currentAvatarUrl;
  159. },
  160. noAvatarUrl() {
  161. const userProfile = Meteor.user().profile;
  162. const avatarUrl = userProfile && userProfile.avatarUrl;
  163. return !avatarUrl;
  164. },
  165. setAvatar(avatarUrl) {
  166. Meteor.user().setAvatarUrl(avatarUrl);
  167. },
  168. setError(error) {
  169. this.error.set(error);
  170. },
  171. events() {
  172. return [
  173. {
  174. 'click .js-upload-avatar'() {
  175. this.$('.js-upload-avatar-input').click();
  176. },
  177. 'change .js-upload-avatar-input'(event) {
  178. const self = this;
  179. if (event.currentTarget.files && event.currentTarget.files[0]) {
  180. const uploader = Avatars.insert(
  181. {
  182. file: event.currentTarget.files[0],
  183. chunkSize: 'dynamic',
  184. },
  185. false,
  186. );
  187. uploader.on('error', (error, fileData) => {
  188. self.setError(error.reason);
  189. });
  190. uploader.start();
  191. }
  192. },
  193. 'click .js-select-avatar'() {
  194. const avatarUrl = `${this.currentData().link()}?auth=false&brokenIsFine=true`;
  195. this.setAvatar(avatarUrl);
  196. },
  197. 'click .js-select-initials'() {
  198. this.setAvatar('');
  199. },
  200. 'click .js-delete-avatar'(event) {
  201. Avatars.remove(this.currentData()._id);
  202. event.stopPropagation();
  203. },
  204. },
  205. ];
  206. },
  207. }).register('changeAvatarPopup');
  208. Template.cardMembersPopup.helpers({
  209. isCardMember() {
  210. const card = Template.parentData();
  211. const cardMembers = card.getMembers();
  212. return _.contains(cardMembers, this.userId);
  213. },
  214. user() {
  215. return ReactiveCache.getUser(this.userId);
  216. },
  217. });
  218. Template.cardMembersPopup.events({
  219. 'click .js-select-member'(event) {
  220. const card = Utils.getCurrentCard();
  221. const memberId = this.userId;
  222. card.toggleMember(memberId);
  223. event.preventDefault();
  224. },
  225. });
  226. Template.cardMemberPopup.helpers({
  227. user() {
  228. return ReactiveCache.getUser(this.userId);
  229. },
  230. });
  231. Template.cardMemberPopup.events({
  232. 'click .js-remove-member'() {
  233. ReactiveCache.getCard(this.cardId).unassignMember(this.userId);
  234. Popup.back();
  235. },
  236. 'click .js-edit-profile': Popup.open('editProfile'),
  237. });