userAvatar.js 7.1 KB

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