123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- import { ReactiveCache } from '/imports/reactiveCache';
- import Cards from '/models/cards';
- import Avatars from '/models/avatars';
- import Users from '/models/users';
- import Org from '/models/org';
- import Team from '/models/team';
- Template.userAvatar.helpers({
- userData() {
- return Users.findOne(this.userId, {
- fields: {
- profile: 1,
- username: 1,
- },
- });
- },
- memberType() {
- const user = ReactiveCache.getUser(this.userId);
- return user && user.isBoardAdmin() ? 'admin' : 'normal';
- },
- /*
- presenceStatusClassName() {
- const user = ReactiveCache.getUser(this.userId);
- const userPresence = presences.findOne({ userId: this.userId });
- if (user && user.isInvitedTo(Session.get('currentBoard'))) return 'pending';
- else if (!userPresence) return 'disconnected';
- else if (Session.equals('currentBoard', userPresence.state.currentBoardId))
- return 'active';
- else return 'idle';
- },
- */
- });
- Template.userAvatarInitials.helpers({
- initials() {
- const user = ReactiveCache.getUser(this.userId);
- return user && user.getInitials();
- },
- viewPortWidth() {
- const user = ReactiveCache.getUser(this.userId);
- return ((user && user.getInitials().length) || 1) * 12;
- },
- });
- BlazeComponent.extendComponent({
- onCreated() {
- this.error = new ReactiveVar('');
- this.loading = new ReactiveVar(false);
- this.findOrgsOptions = new ReactiveVar({});
- this.page = new ReactiveVar(1);
- this.autorun(() => {
- const limitOrgs = this.page.get() * Number.MAX_SAFE_INTEGER;
- this.subscribe('org', this.findOrgsOptions.get(), limitOrgs, () => {});
- });
- },
- onRendered() {
- this.setLoading(false);
- },
- setError(error) {
- this.error.set(error);
- },
- setLoading(w) {
- this.loading.set(w);
- },
- isLoading() {
- return this.loading.get();
- },
- events() {
- return [
- {
- 'keyup input'() {
- this.setError('');
- },
- 'click .js-manage-board-removeOrg': Popup.open('removeBoardOrg'),
- },
- ];
- },
- }).register('boardOrgRow');
- Template.boardOrgRow.helpers({
- orgData() {
- return Org.findOne(this.orgId);
- },
- currentUser(){
- return Meteor.user();
- },
- });
- Template.boardOrgName.helpers({
- orgName() {
- const org = Org.findOne(this.orgId);
- return org && org.orgDisplayName;
- },
- orgViewPortWidth() {
- const org = Org.findOne(this.orgId);
- return ((org && org.orgDisplayName.length) || 1) * 12;
- },
- });
- BlazeComponent.extendComponent({
- onCreated() {
- this.error = new ReactiveVar('');
- this.loading = new ReactiveVar(false);
- this.findOrgsOptions = new ReactiveVar({});
- this.page = new ReactiveVar(1);
- this.autorun(() => {
- const limitTeams = this.page.get() * Number.MAX_SAFE_INTEGER;
- this.subscribe('team', this.findOrgsOptions.get(), limitTeams, () => {});
- });
- },
- onRendered() {
- this.setLoading(false);
- },
- setError(error) {
- this.error.set(error);
- },
- setLoading(w) {
- this.loading.set(w);
- },
- isLoading() {
- return this.loading.get();
- },
- events() {
- return [
- {
- 'keyup input'() {
- this.setError('');
- },
- 'click .js-manage-board-removeTeam': Popup.open('removeBoardTeam'),
- },
- ];
- },
- }).register('boardTeamRow');
- Template.boardTeamRow.helpers({
- teamData() {
- return Team.findOne(this.teamId);
- },
- currentUser(){
- return Meteor.user();
- },
- });
- Template.boardTeamName.helpers({
- teamName() {
- const team = Team.findOne(this.teamId);
- return team && team.teamDisplayName;
- },
- teamViewPortWidth() {
- const team = Team.findOne(this.teamId);
- return ((team && team.teamDisplayName.length) || 1) * 12;
- },
- });
- BlazeComponent.extendComponent({
- onCreated() {
- this.error = new ReactiveVar('');
- Meteor.subscribe('my-avatars');
- },
- uploadedAvatars() {
- return Avatars.find({ userId: Meteor.userId() }).each();
- },
- isSelected() {
- const userProfile = Meteor.user().profile;
- const avatarUrl = userProfile && userProfile.avatarUrl;
- const currentAvatarUrl = `${this.currentData().link()}?auth=false&brokenIsFine=true`;
- return avatarUrl === currentAvatarUrl;
- },
- noAvatarUrl() {
- const userProfile = Meteor.user().profile;
- const avatarUrl = userProfile && userProfile.avatarUrl;
- return !avatarUrl;
- },
- setAvatar(avatarUrl) {
- Meteor.user().setAvatarUrl(avatarUrl);
- },
- setError(error) {
- this.error.set(error);
- },
- events() {
- return [
- {
- 'click .js-upload-avatar'() {
- this.$('.js-upload-avatar-input').click();
- },
- 'change .js-upload-avatar-input'(event) {
- const self = this;
- if (event.currentTarget.files && event.currentTarget.files[0]) {
- const uploader = Avatars.insert(
- {
- file: event.currentTarget.files[0],
- chunkSize: 'dynamic',
- },
- false,
- );
- uploader.on('error', (error, fileData) => {
- self.setError(error.reason);
- });
- uploader.start();
- }
- },
- 'click .js-select-avatar'() {
- const avatarUrl = `${this.currentData().link()}?auth=false&brokenIsFine=true`;
- this.setAvatar(avatarUrl);
- },
- 'click .js-select-initials'() {
- this.setAvatar('');
- },
- 'click .js-delete-avatar'(event) {
- Avatars.remove(this.currentData()._id);
- event.stopPropagation();
- },
- },
- ];
- },
- }).register('changeAvatarPopup');
- Template.cardMembersPopup.helpers({
- isCardMember() {
- const card = Template.parentData();
- const cardMembers = card.getMembers();
- return _.contains(cardMembers, this.userId);
- },
- user() {
- return ReactiveCache.getUser(this.userId);
- },
- });
- Template.cardMembersPopup.events({
- 'click .js-select-member'(event) {
- const card = Utils.getCurrentCard();
- const memberId = this.userId;
- card.toggleMember(memberId);
- event.preventDefault();
- },
- });
- Template.cardMemberPopup.helpers({
- user() {
- return ReactiveCache.getUser(this.userId);
- },
- });
- Template.cardMemberPopup.events({
- 'click .js-remove-member'() {
- ReactiveCache.getCard(this.cardId).unassignMember(this.userId);
- Popup.back();
- },
- 'click .js-edit-profile': Popup.open('editProfile'),
- });
|