2020-08-14 08:46:34 +02:00
|
|
|
import loading from '../../../../components/loading/loading';
|
|
|
|
import libraryMenu from '../../../../scripts/libraryMenu';
|
|
|
|
import globalize from '../../../../scripts/globalize';
|
|
|
|
import dialogHelper from '../../../../components/dialogHelper/dialogHelper';
|
|
|
|
import '../../../../elements/emby-button/emby-button';
|
|
|
|
import '../../../../elements/emby-checkbox/emby-checkbox';
|
|
|
|
import '../../../../elements/emby-select/emby-select';
|
2021-01-26 16:25:38 -05:00
|
|
|
import '../../../../components/formdialog.scss';
|
|
|
|
import '../../../../components/listview/listview.scss';
|
2020-06-10 21:33:08 +09:00
|
|
|
|
|
|
|
let repositories = [];
|
|
|
|
|
|
|
|
function reloadList(page) {
|
|
|
|
loading.show();
|
2020-06-11 03:02:38 +09:00
|
|
|
ApiClient.getJSON(ApiClient.getUrl('Repositories')).then(list => {
|
|
|
|
repositories = list;
|
2020-06-10 21:33:08 +09:00
|
|
|
populateList({
|
|
|
|
listElement: page.querySelector('#repositories'),
|
|
|
|
noneElement: page.querySelector('#none'),
|
2020-06-11 03:02:38 +09:00
|
|
|
repositories: repositories
|
2020-06-10 21:33:08 +09:00
|
|
|
});
|
2021-01-26 22:20:12 -05:00
|
|
|
}).catch(() => {
|
2020-06-11 19:34:06 +09:00
|
|
|
console.error('error loading repositories');
|
2020-06-10 21:33:08 +09:00
|
|
|
page.querySelector('#none').classList.remove('hide');
|
|
|
|
loading.hide();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-16 21:13:07 +09:00
|
|
|
function saveList(page) {
|
2020-06-10 21:33:08 +09:00
|
|
|
loading.show();
|
|
|
|
ApiClient.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: ApiClient.getUrl('Repositories'),
|
|
|
|
data: JSON.stringify(repositories),
|
|
|
|
contentType: 'application/json'
|
2021-01-26 22:20:12 -05:00
|
|
|
}).then(() => {
|
2020-06-16 21:13:07 +09:00
|
|
|
reloadList(page);
|
2021-01-26 22:20:12 -05:00
|
|
|
}).catch(() => {
|
2020-06-11 19:34:06 +09:00
|
|
|
console.error('error saving repositories');
|
2020-06-10 21:33:08 +09:00
|
|
|
loading.hide();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function populateList(options) {
|
2020-10-07 21:12:14 +09:00
|
|
|
let html = '';
|
2020-06-10 21:33:08 +09:00
|
|
|
|
|
|
|
html += '<div class="paperList">';
|
2020-10-07 21:12:14 +09:00
|
|
|
for (let i = 0; i < options.repositories.length; i++) {
|
2020-06-10 21:33:08 +09:00
|
|
|
html += getRepositoryHtml(options.repositories[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
if (!options.repositories.length) {
|
|
|
|
options.noneElement.classList.remove('hide');
|
2021-02-03 16:15:40 +01:00
|
|
|
} else {
|
|
|
|
options.noneElement.classList.add('hide');
|
2020-06-10 21:33:08 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
options.listElement.innerHTML = html;
|
|
|
|
loading.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getRepositoryHtml(repository) {
|
2020-10-07 21:12:14 +09:00
|
|
|
let html = '';
|
2020-06-10 21:33:08 +09:00
|
|
|
|
2020-06-11 03:02:38 +09:00
|
|
|
html += '<div class="listItem listItem-border">';
|
2021-10-05 00:35:30 -04:00
|
|
|
html += `<a is="emby-linkbutton" style="margin:0;padding:0" class="clearLink listItemIconContainer" href="${repository.Url}" rel="noopener noreferrer" target="_blank">`;
|
2022-02-24 20:15:24 +03:00
|
|
|
html += '<span class="material-icons listItemIcon open_in_new" aria-hidden="true"></span>';
|
2020-06-11 19:34:06 +09:00
|
|
|
html += '</a>';
|
2020-06-10 21:33:08 +09:00
|
|
|
html += '<div class="listItemBody two-line">';
|
2020-06-17 02:15:05 +09:00
|
|
|
html += `<h3 class="listItemBodyText">${repository.Name}</h3>`;
|
2020-06-10 21:33:08 +09:00
|
|
|
html += `<div class="listItemBodyText secondary">${repository.Url}</div>`;
|
2020-06-11 03:02:38 +09:00
|
|
|
html += '</div>';
|
2022-02-24 20:15:24 +03:00
|
|
|
html += `<button type="button" is="paper-icon-button-light" id="${repository.Url}" class="btnDelete" title="${globalize.translate('Delete')}"><span class="material-icons delete" aria-hidden="true"></span></button>`;
|
2020-06-11 03:02:38 +09:00
|
|
|
html += '</div>';
|
2020-06-10 21:33:08 +09:00
|
|
|
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTabs() {
|
|
|
|
return [{
|
2020-12-03 16:13:27 -05:00
|
|
|
href: '#!/installedplugins.html',
|
2020-06-10 21:33:08 +09:00
|
|
|
name: globalize.translate('TabMyPlugins')
|
|
|
|
}, {
|
2020-12-03 16:13:27 -05:00
|
|
|
href: '#!/availableplugins.html',
|
2020-06-10 21:33:08 +09:00
|
|
|
name: globalize.translate('TabCatalog')
|
|
|
|
}, {
|
2020-12-03 16:13:27 -05:00
|
|
|
href: '#!/repositories.html',
|
2020-06-10 21:33:08 +09:00
|
|
|
name: globalize.translate('TabRepositories')
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2021-01-26 22:20:12 -05:00
|
|
|
export default function(view) {
|
2020-06-10 21:33:08 +09:00
|
|
|
view.addEventListener('viewshow', function () {
|
|
|
|
libraryMenu.setTabs('plugins', 2, getTabs);
|
|
|
|
reloadList(this);
|
2020-06-11 03:02:38 +09:00
|
|
|
|
2020-10-07 21:12:14 +09:00
|
|
|
const save = this;
|
2020-06-11 03:02:38 +09:00
|
|
|
$('#repositories', view).on('click', '.btnDelete', function() {
|
2020-10-07 21:12:14 +09:00
|
|
|
const button = this;
|
2020-06-11 19:34:06 +09:00
|
|
|
repositories = repositories.filter(function (r) {
|
|
|
|
return r.Url !== button.id;
|
|
|
|
});
|
|
|
|
|
2020-06-16 21:13:07 +09:00
|
|
|
saveList(save);
|
2020-06-11 03:02:38 +09:00
|
|
|
});
|
2020-06-10 21:33:08 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
view.querySelector('.btnNewRepository').addEventListener('click', () => {
|
2020-07-16 22:19:09 +02:00
|
|
|
const dialog = dialogHelper.createDialog({
|
2020-06-10 21:33:08 +09:00
|
|
|
scrollY: false,
|
|
|
|
size: 'large',
|
|
|
|
modal: false,
|
|
|
|
removeOnClose: true
|
|
|
|
});
|
|
|
|
|
|
|
|
let html = '';
|
|
|
|
|
|
|
|
html += '<div class="formDialogHeader">';
|
2022-02-24 19:03:42 +03:00
|
|
|
html += `<button type="button" is="paper-icon-button-light" class="btnCancel autoSize" tabindex="-1" title="${globalize.translate('ButtonBack')}"><span class="material-icons arrow_back" aria-hidden="true"></span></button>`;
|
2020-06-10 21:33:08 +09:00
|
|
|
html += `<h3 class="formDialogHeaderTitle">${globalize.translate('HeaderNewRepository')}</h3>`;
|
|
|
|
html += '</div>';
|
2020-06-11 03:02:38 +09:00
|
|
|
html += '<form class="newPluginForm" style="margin:4em">';
|
2020-06-10 21:33:08 +09:00
|
|
|
html += '<div class="inputContainer">';
|
2020-06-16 21:13:07 +09:00
|
|
|
html += `<input is="emby-input" id="txtRepositoryName" label="${globalize.translate('LabelRepositoryName')}" type="text" required />`;
|
2020-06-10 21:33:08 +09:00
|
|
|
html += `<div class="fieldDescription">${globalize.translate('LabelRepositoryNameHelp')}</div>`;
|
|
|
|
html += '</div>';
|
|
|
|
html += '<div class="inputContainer">';
|
2020-06-16 21:13:07 +09:00
|
|
|
html += `<input is="emby-input" id="txtRepositoryUrl" label="${globalize.translate('LabelRepositoryUrl')}" type="url" required />`;
|
2020-06-10 21:33:08 +09:00
|
|
|
html += `<div class="fieldDescription">${globalize.translate('LabelRepositoryUrlHelp')}</div>`;
|
|
|
|
html += '</div>';
|
2020-08-09 23:10:58 +09:00
|
|
|
html += `<button is="emby-button" type="submit" class="raised button-submit block"><span>${globalize.translate('Save')}</span></button>`;
|
2020-06-10 21:33:08 +09:00
|
|
|
html += '</div>';
|
|
|
|
html += '</form>';
|
|
|
|
|
|
|
|
dialog.innerHTML = html;
|
|
|
|
dialog.querySelector('.btnCancel').addEventListener('click', () => {
|
|
|
|
dialogHelper.close(dialog);
|
|
|
|
});
|
|
|
|
|
2020-12-03 14:44:32 -05:00
|
|
|
dialog.querySelector('.newPluginForm').addEventListener('submit', e => {
|
|
|
|
e.preventDefault();
|
|
|
|
|
2020-06-10 21:33:08 +09:00
|
|
|
repositories.push({
|
|
|
|
Name: dialog.querySelector('#txtRepositoryName').value,
|
|
|
|
Url: dialog.querySelector('#txtRepositoryUrl').value,
|
|
|
|
Enabled: true
|
|
|
|
});
|
|
|
|
|
2020-06-16 21:13:07 +09:00
|
|
|
saveList(view);
|
2020-06-10 21:33:08 +09:00
|
|
|
dialogHelper.close(dialog);
|
2020-06-11 19:34:06 +09:00
|
|
|
return false;
|
2020-06-10 21:33:08 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
dialogHelper.open(dialog);
|
|
|
|
});
|
|
|
|
}
|