Skip to content

Commit

Permalink
refactor(sources-file): refactor a huge amount of identified issues t…
Browse files Browse the repository at this point in the history
…o pass code quality test
  • Loading branch information
FlorentinTh committed Jan 21, 2022
1 parent bc67604 commit aff78c1
Show file tree
Hide file tree
Showing 33 changed files with 1,446 additions and 1,061 deletions.
2 changes: 1 addition & 1 deletion src/components/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Component {
Router.setRoute(URLHelper.getPage() + href);

if (href.includes('machine-learning') || href.includes('deep-learning')) {
const pipeline = href.substring(1).replace('-', '_');
const pipeline = href.substring(1).replace(/-/g, '_');
sessionStorage.setItem('pipeline', pipeline);
}
});
Expand Down
231 changes: 135 additions & 96 deletions src/components/admin/administration/app-keys/AppKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ class AppKeys extends Component {

if (this.reload || sotredAppKeys === undefined) {
this.initView(true);
getKeys('/apps/keys', this.context).then(response => {
if (response) {
Store.add({
id: 'app-keys',
data: response.data
});
allAppKeys = response.data;
this.render();
}
});
getKeys('/apps/keys', this.context)
.then(response => {
if (response) {
Store.add({
id: 'app-keys',
data: response.data
});
allAppKeys = response.data;
this.render();
}
})
.catch(error => {
ModalHelper.notification('error', error);
});
} else {
this.render();
}
Expand Down Expand Up @@ -136,20 +140,28 @@ class AppKeys extends Component {
const askMessage =
'Every single key will be permanently revoked and applications using them may no longer work properly. Make sure all of their creators agreed with such a change.';

ModalHelper.confirm(askTitle, askMessage).then(result => {
if (result.value) {
revokeKeys('/apps/keys/revoke', this.context).then(response => {
if (response) {
ModalHelper.notification(
'success',
response.data.total + ' keys successfully revoked.'
);
// eslint-disable-next-line no-new
new AppKeys(true);
}
});
}
});
ModalHelper.confirm(askTitle, askMessage)
.then(result => {
if (result.value) {
revokeKeys('/apps/keys/revoke', this.context)
.then(response => {
if (response) {
ModalHelper.notification(
'success',
response.data.total + ' keys successfully revoked.'
);
// eslint-disable-next-line no-new
new AppKeys(true);
}
})
.catch(error => {
ModalHelper.notification('error', error);
});
}
})
.catch(error => {
ModalHelper.notification('error', error);
});
}

addBtnListener(event) {
Expand All @@ -159,57 +171,65 @@ class AppKeys extends Component {
const content = formAppKeysTemplate({ update: false });
const elems = ['name', 'description'];

ModalHelper.edit('Generate a new app key', content, 'generate', elems).then(
result => {
ModalHelper.edit('Generate a new app key', content, 'generate', elems)
.then(result => {
if (result.value) {
const data = {
name: result.value.name.toLowerCase(),
description: result.value.description.toLowerCase()
};

generateKey('/apps/keys/generate', data, this.context).then(response => {
if (response) {
const content = formCopyKeyTemplate({ key: response.data.app.key });
const elems = ['key'];

ModalHelper.edit('Your new app key', content, 'OK', elems, false).then(
response => {
if (response) {
// eslint-disable-next-line no-new
new AppKeys(true);
}
}
);

const copyBtn = document.querySelector('button#copy-key');
copyBtn.addEventListener(
'click',
event => {
event.preventDefault();
event.stopImmediatePropagation();
const keyInput = document.querySelector('input#key');

keyInput.select();
keyInput.setSelectionRange(0, 99999);
document.execCommand('copy');

if (window.getSelection) {
window.getSelection().removeAllRanges();
} else {
document.selection.empty();
}

copyBtn.children[0].classList.remove('far', 'fa-clipboard');
copyBtn.children[0].classList.add('fas', 'fa-check');
copyBtn.disabled = true;
},
false
);
}
});
generateKey('/apps/keys/generate', data, this.context)
.then(response => {
if (response) {
const content = formCopyKeyTemplate({ key: response.data.app.key });
const elems = ['key'];

ModalHelper.edit('Your new app key', content, 'OK', elems, false)
.then(response => {
if (response) {
// eslint-disable-next-line no-new
new AppKeys(true);
}
})
.catch(error => {
ModalHelper.notification('error', error);
});

const copyBtn = document.querySelector('button#copy-key');
copyBtn.addEventListener(
'click',
event => {
event.preventDefault();
event.stopImmediatePropagation();
const keyInput = document.querySelector('input#key');

keyInput.select();
keyInput.setSelectionRange(0, 99999);
document.execCommand('copy');

if (window.getSelection) {
window.getSelection().removeAllRanges();
} else {
document.selection.empty();
}

copyBtn.children[0].classList.remove('far', 'fa-clipboard');
copyBtn.children[0].classList.add('fas', 'fa-check');
copyBtn.disabled = true;
},
false
);
}
})
.catch(error => {
ModalHelper.notification('error', error);
});
}
}
);
})
.catch(error => {
ModalHelper.notification('error', error);
});
}

setActions(appKeys) {
Expand All @@ -222,7 +242,7 @@ class AppKeys extends Component {

buttons.forEach(button => {
const appKeyId = button.closest('#app-key-infos').dataset.key;
const key = appKeys.find(elem => elem._id === appKeyId);
const key = Array.prototype.find.call(appKeys, elem => elem._id === appKeyId);

button.addEventListener('click', event => {
event.preventDefault();
Expand All @@ -231,17 +251,28 @@ class AppKeys extends Component {
const askTitle = 'Revoke key ?';
const askMessage = `${key.name} will be permanently revoked and applications using it may no longer work properly. Make sure its creator agreed with such a change.`;

ModalHelper.confirm(askTitle, askMessage).then(result => {
if (result.value) {
revokeKeys('/apps/keys/revoke/' + appKeyId, this.context).then(response => {
if (response) {
ModalHelper.notification('success', key.name + ' successfully revoked.');
// eslint-disable-next-line no-new
new AppKeys(true);
}
});
}
});
ModalHelper.confirm(askTitle, askMessage)
.then(result => {
if (result.value) {
revokeKeys('/apps/keys/revoke/' + appKeyId, this.context)
.then(response => {
if (response) {
ModalHelper.notification(
'success',
key.name + ' successfully revoked.'
);
// eslint-disable-next-line no-new
new AppKeys(true);
}
})
.catch(error => {
ModalHelper.notification('error', error);
});
}
})
.catch(error => {
ModalHelper.notification('error', error);
});
});
});
}
Expand All @@ -251,7 +282,7 @@ class AppKeys extends Component {

buttons.forEach(button => {
const appKeyId = button.closest('#app-key-infos').dataset.key;
const key = appKeys.find(elem => elem._id === appKeyId);
const key = Array.prototype.find.call(appKeys, elem => elem._id === appKeyId);

button.addEventListener('click', event => {
event.preventDefault();
Expand All @@ -264,21 +295,29 @@ class AppKeys extends Component {

const elems = ['name', 'description'];

ModalHelper.edit('Edit app key', content, 'update', elems).then(result => {
if (result.value) {
const data = result.value;
updateKey('/apps/keys/' + appKeyId, data, this.context).then(response => {
if (response) {
ModalHelper.notification(
'success',
response.data.appKey.name + ' successfully updated'
);
// eslint-disable-next-line no-new
new AppKeys(true);
}
});
}
});
ModalHelper.edit('Edit app key', content, 'update', elems)
.then(result => {
if (result.value) {
const data = result.value;
updateKey('/apps/keys/' + appKeyId, data, this.context)
.then(response => {
if (response) {
ModalHelper.notification(
'success',
response.data.appKey.name + ' successfully updated'
);
// eslint-disable-next-line no-new
new AppKeys(true);
}
})
.catch(error => {
ModalHelper.notification('error', error);
});
}
})
.catch(error => {
ModalHelper.notification('error', error);
});
});
});
}
Expand Down
3 changes: 3 additions & 0 deletions src/components/admin/administration/jobs-log/JobsLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ class JobsLog extends Component {
if (response) {
fileDownload(response.data, 'jobs.log');
}
})
.catch(error => {
ModalHelper.notification('error', error);
});
}

Expand Down

0 comments on commit aff78c1

Please sign in to comment.