Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Change components, routes, services, etc to native classes #4294

Merged
merged 6 commits into from
Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module.exports = {
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module'
sourceType: 'module',
ecmaFeatures: { legacyDecorators: true },
},
plugins: [
'ember',
Expand Down
77 changes: 40 additions & 37 deletions app/components/account/application-section.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,50 @@
import Component from '@ember/component';
import classic from 'ember-classic-decorator';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import Component from '@ember/component';

export default Component.extend({
torii: service(),
@classic
export default class ApplicationSection extends Component {
@service
torii;

isLoading: false,
isLoading = false;

actions: {
auth(provider) {
try {
if (provider === 'facebook') {
this.torii.open('facebook').then(authData => {
this.set('isLoading', true);
this.loader.load(`/auth/oauth/login/${ provider }/${ authData.authorizationCode }/?redirect_uri=${ authData.redirectUri}`)
.then(async response => {
let credentials = {
'username' : response.email,
'password' : response.facebook_login_hash
};
@action
auth(provider) {
try {
if (provider === 'facebook') {
this.torii.open('facebook').then(authData => {
this.set('isLoading', true);
this.loader.load(`/auth/oauth/login/${ provider }/${ authData.authorizationCode }/?redirect_uri=${ authData.redirectUri}`)
.then(async response => {
let credentials = {
'username' : response.email,
'password' : response.facebook_login_hash
};

let authenticator = 'authenticator:jwt';
this.session
.authenticate(authenticator, credentials)
.then(async() => {
const tokenPayload = this.authManager.getTokenPayload();
if (tokenPayload) {
this.authManager.persistCurrentUser(
await this.store.findRecord('user', tokenPayload.identity)
);
this.set('data', this.authManager.currentUser);
}
let authenticator = 'authenticator:jwt';
this.session
.authenticate(authenticator, credentials)
.then(async() => {
const tokenPayload = this.authManager.getTokenPayload();
if (tokenPayload) {
this.authManager.persistCurrentUser(
await this.store.findRecord('user', tokenPayload.identity)
);
this.set('data', this.authManager.currentUser);
}

this.set('isLoading', false);
});
});
});
}
} catch (error) {
this.notify.error(this.l10n.t(error.message), {
id: 'error_message'
this.set('isLoading', false);
});
});
});
this.set('isLoading', false);
}
} catch (error) {
this.notify.error(this.l10n.t(error.message), {
id: 'error_message'
});
this.set('isLoading', false);
}
}
});
}
97 changes: 51 additions & 46 deletions app/components/account/danger-zone.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,60 @@
import { computed } from '@ember/object';
import classic from 'ember-classic-decorator';
import { action, computed } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({

isUserDeletable: computed('data.events', 'data.orders', function() {
@classic
export default class DangerZone extends Component {
@computed('data.events', 'data.orders')
get isUserDeletable() {
if (this.data.events.length || this.data.orders.length) {
return false;
}
return true;
}),
}

actions: {
openDeleteUserModal(id, email) {
this.setProperties({
'isUserDeleteModalOpen' : true,
'confirmEmail' : '',
'userEmail' : email,
'userId' : id
});
},
openConfirmDeleteUserModal() {
this.setProperties({
'isUserDeleteModalOpen' : false,
'confirmEmail' : '',
'isConfirmUserDeleteModalOpen' : true,
'checked' : false
});
},
deleteUser(user) {
this.set('isLoading', true);
user.destroyRecord()
.then(() => {
this.authManager.logout();
this.routing.transitionTo('index');
this.notify.success(this.l10n.t('Your account has been deleted successfully.'), {
id: 'account_Delete'
});
})
.catch(e => {
console.error('Error while deleting account', e);
this.notify.error(this.l10n.t('An unexpected error has occurred.'), {
id: 'account_del_error'
});
})
.finally(() => {
this.setProperties({
'isLoading' : false,
'isConfirmUserDeleteModalOpen' : false,
'checked' : false
});
@action
openDeleteUserModal(id, email) {
this.setProperties({
'isUserDeleteModalOpen' : true,
'confirmEmail' : '',
'userEmail' : email,
'userId' : id
});
}

@action
openConfirmDeleteUserModal() {
this.setProperties({
'isUserDeleteModalOpen' : false,
'confirmEmail' : '',
'isConfirmUserDeleteModalOpen' : true,
'checked' : false
});
}

@action
deleteUser(user) {
this.set('isLoading', true);
user.destroyRecord()
.then(() => {
this.authManager.logout();
this.routing.transitionTo('index');
this.notify.success(this.l10n.t('Your account has been deleted successfully.'), {
id: 'account_Delete'
});
}
})
.catch(e => {
console.error('Error while deleting account', e);
this.notify.error(this.l10n.t('An unexpected error has occurred.'), {
id: 'account_del_error'
});
})
.finally(() => {
this.setProperties({
'isLoading' : false,
'isConfirmUserDeleteModalOpen' : false,
'checked' : false
});
});
}
});
}
36 changes: 19 additions & 17 deletions app/components/account/email-preferences-section.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import classic from 'ember-classic-decorator';
import { action } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
actions: {
savePreference(emailPreference) {
emailPreference.save()
.then(() => {
this.notify.success(this.l10n.t('Email notifications updated successfully'), {
id: 'email_notif'
});
})
.catch(e => {
console.error('Error while updating email notifications.', e);
emailPreference.rollbackAttributes();
this.notify.error(this.l10n.t('An unexpected error occurred.'), {
id: 'email_error'
});
@classic
export default class EmailPreferencesSection extends Component {
@action
savePreference(emailPreference) {
emailPreference.save()
.then(() => {
this.notify.success(this.l10n.t('Email notifications updated successfully'), {
id: 'email_notif'
});
}
})
.catch(e => {
console.error('Error while updating email notifications.', e);
emailPreference.rollbackAttributes();
this.notify.error(this.l10n.t('An unexpected error occurred.'), {
id: 'email_error'
});
});
}
});
}
21 changes: 15 additions & 6 deletions app/components/create-session-message.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import Component from '@ember/component';
import { tracked } from '@glimmer/tracking';
import classic from 'ember-classic-decorator';
import { computed } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
@classic
export default class CreateSessionMessage extends Component {
@tracked isMessageVisible = true;

isMessageVisible : true,
shouldShowMessage : computed('session.isAuthenticated', 'isMessageVisible', 'isNewSpeaker', 'isNewSession', function() {
@computed(
'session.isAuthenticated',
'isMessageVisible',
'isNewSpeaker',
'isNewSession'
)
get shouldShowMessage() {
let speakerIDlength = this.data.userSpeaker ? this.data.userSpeaker.toArray().length : 0;
return this.session.isAuthenticated
&& this.isMessageVisible
&& !this.isNewSpeaker
&& this.isNewSession
&& (speakerIDlength > 0);
})
});
}
}
5 changes: 3 additions & 2 deletions app/components/errors/forbidden-error.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import classic from 'ember-classic-decorator';
import Component from '@ember/component';

export default Component.extend({
});
@classic
export default class ForbiddenError extends Component {}
5 changes: 3 additions & 2 deletions app/components/errors/generic-error.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import classic from 'ember-classic-decorator';
import Component from '@ember/component';

export default Component.extend({
});
@classic
export default class GenericError extends Component {}
5 changes: 3 additions & 2 deletions app/components/errors/not-found.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import classic from 'ember-classic-decorator';
import Component from '@ember/component';

export default Component.extend({
});
@classic
export default class NotFound extends Component {}
5 changes: 3 additions & 2 deletions app/components/errors/server-error.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import classic from 'ember-classic-decorator';
import Component from '@ember/component';

export default Component.extend({
});
@classic
export default class ServerError extends Component {}
33 changes: 18 additions & 15 deletions app/components/event-card.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import classic from 'ember-classic-decorator';
import { classNames } from '@ember-decorators/component';
import { action, computed } from '@ember/object';
import Component from '@ember/component';
import { computed } from '@ember/object';
import { forOwn } from 'lodash-es';
import { pascalCase } from 'open-event-frontend/utils/string';

export default Component.extend({
classNames: ['column'],

tags: computed('event.type', 'event.topic', 'event.subTopic', function() {
@classic
@classNames('column')
export default class EventCard extends Component {
@computed('event.type', 'event.topic', 'event.subTopic')
get tags() {
// Unfortunately, due to the extremely dynamic and stringy nature
// of ember, the next line crashes on using object destructuring
// and we don't have time and resources to chase down issues originating
Expand All @@ -19,16 +22,16 @@ export default Component.extend({
}
});
return tags;
}),
}

actions: {
selectCategory(category, subCategory) {
this.set('category', (category === this.category && !subCategory) ? null : category);
this.set('subCategory', (!subCategory || subCategory === this.subCategory) ? null : subCategory);
},
@action
selectCategory(category, subCategory) {
this.set('category', (category === this.category && !subCategory) ? null : category);
this.set('subCategory', (!subCategory || subCategory === this.subCategory) ? null : subCategory);
}

selectEventType(eventType) {
this.set('eventType', eventType === this.eventType ? null : eventType);
}
@action
selectEventType(eventType) {
this.set('eventType', eventType === this.eventType ? null : eventType);
}
});
}
5 changes: 3 additions & 2 deletions app/components/event-invoice/billing-info.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import classic from 'ember-classic-decorator';
import Component from '@ember/component';

export default Component.extend({
});
@classic
export default class BillingInfo extends Component {}
5 changes: 3 additions & 2 deletions app/components/event-invoice/event-info.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import classic from 'ember-classic-decorator';
import Component from '@ember/component';

export default Component.extend({
});
@classic
export default class EventInfo extends Component {}
5 changes: 3 additions & 2 deletions app/components/event-invoice/invoice-summary.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import classic from 'ember-classic-decorator';
import Component from '@ember/component';

export default Component.extend({
});
@classic
export default class InvoiceSummary extends Component {}
5 changes: 3 additions & 2 deletions app/components/event-invoice/payee-info.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import classic from 'ember-classic-decorator';
import Component from '@ember/component';

export default Component.extend({
});
@classic
export default class PayeeInfo extends Component {}
8 changes: 5 additions & 3 deletions app/components/events/events-table.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import classic from 'ember-classic-decorator';
import { classNames } from '@ember-decorators/component';
import UiTable from 'open-event-frontend/components/ui-table-server';

export default UiTable.extend({
classNames: ['ui', 'main-container']
});
@classic
@classNames('ui', 'main-container')
export default class EventsTable extends UiTable {}
Loading