Prettier & eslint project style update

This commit is contained in:
Justin Reynolds 2019-06-28 12:52:09 -05:00
parent a0a482aa8e
commit 3eb4d2c341
116 changed files with 6216 additions and 5240 deletions

View file

@ -9,10 +9,15 @@ Template.editor.onRendered(() => {
match: /\B@([\w.]*)$/,
search(term, callback) {
const currentBoard = Boards.findOne(Session.get('currentBoard'));
callback(currentBoard.activeMembers().map((member) => {
const username = Users.findOne(member.userId).username;
return username.includes(term) ? username : null;
}).filter(Boolean));
callback(
currentBoard
.activeMembers()
.map(member => {
const username = Users.findOne(member.userId).username;
return username.includes(term) ? username : null;
})
.filter(Boolean),
);
},
template(value) {
return value;
@ -33,69 +38,73 @@ import sanitizeXss from 'xss';
// compiled version to most users -- who don't need to edit.
// In the meantime, all the transformation are done on the client using the
// Blaze API.
const at = HTML.CharRef({html: '@', str: '@'});
Blaze.Template.registerHelper('mentions', new Template('mentions', function() {
const view = this;
let content = Blaze.toHTML(view.templateContentBlock);
const currentBoard = Boards.findOne(Session.get('currentBoard'));
if (!currentBoard)
const at = HTML.CharRef({ html: '@', str: '@' });
Blaze.Template.registerHelper(
'mentions',
new Template('mentions', function() {
const view = this;
let content = Blaze.toHTML(view.templateContentBlock);
const currentBoard = Boards.findOne(Session.get('currentBoard'));
if (!currentBoard) return HTML.Raw(sanitizeXss(content));
const knowedUsers = currentBoard.members.map(member => {
const u = Users.findOne(member.userId);
if (u) {
member.username = u.username;
}
return member;
});
const mentionRegex = /\B@([\w.]*)/gi;
let currentMention;
while ((currentMention = mentionRegex.exec(content)) !== null) {
const [fullMention, username] = currentMention;
const knowedUser = _.findWhere(knowedUsers, { username });
if (!knowedUser) {
continue;
}
const linkValue = [' ', at, knowedUser.username];
let linkClass = 'atMention js-open-member';
if (knowedUser.userId === Meteor.userId()) {
linkClass += ' me';
}
const link = HTML.A(
{
class: linkClass,
// XXX Hack. Since we stringify this render function result below with
// `Blaze.toHTML` we can't rely on blaze data contexts to pass the
// `userId` to the popup as usual, and we need to store it in the DOM
// using a data attribute.
'data-userId': knowedUser.userId,
},
linkValue,
);
content = content.replace(fullMention, Blaze.toHTML(link));
}
return HTML.Raw(sanitizeXss(content));
const knowedUsers = currentBoard.members.map((member) => {
const u = Users.findOne(member.userId);
if(u){
member.username = u.username;
}
return member;
});
const mentionRegex = /\B@([\w.]*)/gi;
let currentMention;
while ((currentMention = mentionRegex.exec(content)) !== null) {
const [fullMention, username] = currentMention;
const knowedUser = _.findWhere(knowedUsers, { username });
if (!knowedUser) {
continue;
}
const linkValue = [' ', at, knowedUser.username];
let linkClass = 'atMention js-open-member';
if (knowedUser.userId === Meteor.userId()) {
linkClass += ' me';
}
const link = HTML.A({
'class': linkClass,
// XXX Hack. Since we stringify this render function result below with
// `Blaze.toHTML` we can't rely on blaze data contexts to pass the
// `userId` to the popup as usual, and we need to store it in the DOM
// using a data attribute.
'data-userId': knowedUser.userId,
}, linkValue);
content = content.replace(fullMention, Blaze.toHTML(link));
}
return HTML.Raw(sanitizeXss(content));
}));
}),
);
Template.viewer.events({
// Viewer sometimes have click-able wrapper around them (for instance to edit
// the corresponding text). Clicking a link shouldn't fire these actions, stop
// we stop these event at the viewer component level.
'click a'(evt, tpl) {
evt.stopPropagation();
'click a'(event, templateInstance) {
event.stopPropagation();
// XXX We hijack the build-in browser action because we currently don't have
// `_blank` attributes in viewer links, and the transformer function is
// handled by a third party package that we can't configure easily. Fix that
// by using directly `_blank` attribute in the rendered HTML.
evt.preventDefault();
event.preventDefault();
const userId = evt.currentTarget.dataset.userid;
const userId = event.currentTarget.dataset.userid;
if (userId) {
Popup.open('member').call({ userId }, evt, tpl);
}
else {
const href = evt.currentTarget.href;
Popup.open('member').call({ userId }, event, templateInstance);
} else {
const href = event.currentTarget.href;
if (href) {
window.open(href, '_blank');
}

View file

@ -20,13 +20,13 @@ Template.header.helpers({
},
hasAnnouncement() {
const announcements = Announcements.findOne();
const announcements = Announcements.findOne();
return announcements && announcements.enabled;
},
announcement() {
$('.announcement').show();
const announcements = Announcements.findOne();
const announcements = Announcements.findOne();
return announcements && announcements.body;
},
});

View file

@ -1,6 +1,6 @@
BlazeLayout.setRoot('body');
const i18nTagToT9n = (i18nTag) => {
const i18nTagToT9n = i18nTag => {
// t9n/i18n tags are same now, see: https://github.com/softwarerero/meteor-accounts-t9n/pull/129
// but we keep this conversion function here, to be aware that that they are different system.
return i18nTag;
@ -21,20 +21,23 @@ const validator = {
};
Template.userFormsLayout.onCreated(function() {
const instance = this;
instance.currentSetting = new ReactiveVar();
instance.isLoading = new ReactiveVar(false);
const templateInstance = this;
templateInstance.currentSetting = new ReactiveVar();
templateInstance.isLoading = new ReactiveVar(false);
Meteor.subscribe('setting', {
onReady() {
instance.currentSetting.set(Settings.findOne());
templateInstance.currentSetting.set(Settings.findOne());
return this.stop();
},
});
});
Template.userFormsLayout.onRendered(() => {
AccountsTemplates.state.form.keys = new Proxy(AccountsTemplates.state.form.keys, validator);
AccountsTemplates.state.form.keys = new Proxy(
AccountsTemplates.state.form.keys,
validator,
);
const i18nTag = navigator.language;
if (i18nTag) {
@ -89,18 +92,17 @@ Template.userFormsLayout.helpers({
});
Template.userFormsLayout.events({
'change .js-userform-set-language'(evt) {
const i18nTag = $(evt.currentTarget).val();
'change .js-userform-set-language'(event) {
const i18nTag = $(event.currentTarget).val();
T9n.setLanguage(i18nTagToT9n(i18nTag));
evt.preventDefault();
event.preventDefault();
},
'click #at-btn'(event, instance) {
'click #at-btn'(event, templateInstance) {
if (FlowRouter.getRouteName() === 'atSignIn') {
instance.isLoading.set(true);
authentication(event, instance)
.then(() => {
instance.isLoading.set(false);
});
templateInstance.isLoading.set(true);
authentication(event, templateInstance).then(() => {
templateInstance.isLoading.set(false);
});
}
},
});
@ -111,13 +113,16 @@ Template.defaultLayout.events({
},
});
async function authentication(event, instance) {
async function authentication(event, templateInstance) {
const match = $('#at-field-username_and_email').val();
const password = $('#at-field-password').val();
if (!match || !password) return undefined;
const result = await getAuthenticationMethod(instance.currentSetting.get(), match);
const result = await getAuthenticationMethod(
templateInstance.currentSetting.get(),
match,
);
if (result === 'password') return undefined;
@ -126,26 +131,29 @@ async function authentication(event, instance) {
event.stopImmediatePropagation();
switch (result) {
case 'ldap':
return new Promise((resolve) => {
Meteor.loginWithLDAP(match, password, function() {
resolve(FlowRouter.go('/'));
case 'ldap':
return new Promise(resolve => {
Meteor.loginWithLDAP(match, password, function() {
resolve(FlowRouter.go('/'));
});
});
});
case 'cas':
return new Promise((resolve) => {
Meteor.loginWithCas(match, password, function() {
resolve(FlowRouter.go('/'));
case 'cas':
return new Promise(resolve => {
Meteor.loginWithCas(match, password, function() {
resolve(FlowRouter.go('/'));
});
});
});
default:
return undefined;
default:
return undefined;
}
}
function getAuthenticationMethod({displayAuthenticationMethod, defaultAuthenticationMethod}, match) {
function getAuthenticationMethod(
{ displayAuthenticationMethod, defaultAuthenticationMethod },
match,
) {
if (displayAuthenticationMethod) {
return $('.select-authentication').val();
}
@ -153,7 +161,7 @@ function getAuthenticationMethod({displayAuthenticationMethod, defaultAuthentica
}
function getUserAuthenticationMethod(defaultAuthenticationMethod, match) {
return new Promise((resolve) => {
return new Promise(resolve => {
try {
Meteor.subscribe('user-authenticationMethod', match, {
onReady() {
@ -166,7 +174,7 @@ function getUserAuthenticationMethod(defaultAuthenticationMethod, match) {
resolve(authenticationMethod);
},
});
} catch(error) {
} catch (error) {
resolve(defaultAuthenticationMethod);
}
});