Verified Commit fe1298dd authored by Sandro Lutz's avatar Sandro Lutz
Browse files

Update PaginationController

* Add reload() function [PaginationController]
* Add delete() function [StudydocsController]
parent a5f6d0b7
...@@ -24,11 +24,13 @@ ButtonCSS.addStyle('.blue-flat-button', { ...@@ -24,11 +24,13 @@ ButtonCSS.addStyle('.blue-flat-button', {
ButtonCSS.addStyle('.red-flat-button', { ButtonCSS.addStyle('.red-flat-button', {
color_light_background: 'transparent', color_light_background: 'transparent',
color_light_border: '#e8462b',
color_light_text: '#e8462b', color_light_text: '#e8462b',
}); });
ButtonCSS.addStyle('.flat-button', { ButtonCSS.addStyle('.flat-button', {
color_light_background: 'transparent', color_light_background: 'transparent',
color_light_border: 'black',
color_light_text: 'black', color_light_text: 'black',
}); });
......
...@@ -210,6 +210,12 @@ export default { ...@@ -210,6 +210,12 @@ export default {
lecturePlaceholder: 'Vorlesung hier eintippen', lecturePlaceholder: 'Vorlesung hier eintippen',
loadingError: 'Ups, die Filteroptionen konnten nicht geladen werden.', loadingError: 'Ups, die Filteroptionen konnten nicht geladen werden.',
}, },
actions: {
edit: 'bearbeiten',
delete: 'löschen',
cancel: 'abbrechen',
confirm: 'bestätigen',
},
departments: { departments: {
all: 'Alle', all: 'Alle',
other: 'Andere', other: 'Andere',
......
...@@ -209,6 +209,12 @@ export default { ...@@ -209,6 +209,12 @@ export default {
lecturePlaceholder: 'Type lecture name', lecturePlaceholder: 'Type lecture name',
loadingError: 'Oops, we could not load the filter values.', loadingError: 'Oops, we could not load the filter values.',
}, },
actions: {
edit: 'edit',
delete: 'delete',
cancel: 'cancel',
confirm: 'confirm',
},
departments: { departments: {
all: 'All', all: 'All',
other: 'Other', other: 'Other',
......
...@@ -91,16 +91,22 @@ export default class EventController { ...@@ -91,16 +91,22 @@ export default class EventController {
this.openRegistrationEvents.setQuery(this.query); this.openRegistrationEvents.setQuery(this.query);
this.upcomingEvents.setQuery(this.query); this.upcomingEvents.setQuery(this.query);
this.pastEvents.setQuery(this.query); this.pastEvents.setQuery(this.query);
await this.refresh();
const jobs = [
this.openRegistrationEvents.loadAll(),
this.upcomingEvents.loadAll(),
this.pastEvents.loadPageData(1),
];
await Promise.all(jobs);
return true; return true;
} }
/** Refresh all event data */ /** Reload all event data */
async refresh() { async reload() {
const jobs = [ const jobs = [
this.openRegistrationEvents.loadAll(), this.openRegistrationEvents.loadAll(),
this.upcomingEvents.loadAll(), this.upcomingEvents.loadAll(),
this.pastEvents.loadPageData(1), this.pastEvents.reload(),
]; ];
await Promise.all(jobs); await Promise.all(jobs);
} }
......
...@@ -167,6 +167,28 @@ export default class PaginationController { ...@@ -167,6 +167,28 @@ export default class PaginationController {
return data; return data;
} }
/**
* Reload the data from the API using the configured query.
* @return {Promise}
* @public
*/
async reload() {
const numberOfLoadedPages = this.lastLoadedPage;
this._pages = [];
// load first page to get the number of available pages.
await this.loadPageData(1);
let currentPage = 2;
const pagesToLoad = Math.min(numberOfLoadedPages, this.totalPages);
const promiseList = [];
while (currentPage <= pagesToLoad) {
promiseList.push(this.loadPageData(currentPage));
currentPage += 1;
}
await Promise.all(promiseList);
}
/** /**
* Process a response from the API. * Process a response from the API.
* *
......
...@@ -127,6 +127,17 @@ export default class StudydocsController extends PaginationController { ...@@ -127,6 +127,17 @@ export default class StudydocsController extends PaginationController {
}); });
} }
static delete(id, etag) {
return m.request({
method: 'DELETE',
url: `${apiUrl}/studydocuments/${id}`,
headers: {
Authorization: getToken(),
'If-Match': etag,
},
});
}
/** /**
* Additional processing of the API responses to get the * Additional processing of the API responses to get the
* `_summary` values for the studydocuments resource. * `_summary` values for the studydocuments resource.
......
...@@ -48,7 +48,7 @@ export default class EventList extends FilteredListPage { ...@@ -48,7 +48,7 @@ export default class EventList extends FilteredListPage {
// eslint-disable-next-line class-methods-use-this // eslint-disable-next-line class-methods-use-this
_reloadData() { _reloadData() {
return controller.refresh(); return controller.reload();
} }
get _filterViewAttributes() { get _filterViewAttributes() {
......
...@@ -40,7 +40,7 @@ export default class JobofferList extends FilteredListPage { ...@@ -40,7 +40,7 @@ export default class JobofferList extends FilteredListPage {
// eslint-disable-next-line class-methods-use-this // eslint-disable-next-line class-methods-use-this
_reloadData() { _reloadData() {
return controller.loadPageData(1); return controller.reload();
} }
get _filterViewAttributes() { get _filterViewAttributes() {
......
...@@ -15,6 +15,7 @@ import StudydocQuickFilter from './studydocQuickFilter'; ...@@ -15,6 +15,7 @@ import StudydocQuickFilter from './studydocQuickFilter';
import { Infobox } from '../errors'; import { Infobox } from '../errors';
import icons from '../../images/icons'; import icons from '../../images/icons';
import { copyToClipboard } from '../../utils'; import { copyToClipboard } from '../../utils';
import * as log from '../../models/log';
const controller = new StudydocsController(); const controller = new StudydocsController();
const dataStore = new FilteredListDataStore(); const dataStore = new FilteredListDataStore();
...@@ -24,6 +25,7 @@ export default class StudydocList extends FilteredListPage { ...@@ -24,6 +25,7 @@ export default class StudydocList extends FilteredListPage {
super('studydocuments', dataStore); super('studydocuments', dataStore);
this.dropdownDisabled = {}; this.dropdownDisabled = {};
this.deleteDocument = { id: null, busy: false };
this.directLinkCopied = null; this.directLinkCopied = null;
this.directLinkCopiedTimeout = null; this.directLinkCopiedTimeout = null;
} }
...@@ -49,7 +51,7 @@ export default class StudydocList extends FilteredListPage { ...@@ -49,7 +51,7 @@ export default class StudydocList extends FilteredListPage {
// eslint-disable-next-line class-methods-use-this // eslint-disable-next-line class-methods-use-this
_reloadData() { _reloadData() {
return controller.loadPageData(1); return controller.reload();
} }
_isDropdownDisabled(field) { _isDropdownDisabled(field) {
...@@ -263,6 +265,7 @@ export default class StudydocList extends FilteredListPage { ...@@ -263,6 +265,7 @@ export default class StudydocList extends FilteredListPage {
} }
const studydocument = item; const studydocument = item;
const actionButtons = [];
const animationDuration = 300; // in ms const animationDuration = 300; // in ms
const properties = []; const properties = [];
...@@ -292,6 +295,59 @@ export default class StudydocList extends FilteredListPage { ...@@ -292,6 +295,59 @@ export default class StudydocList extends FilteredListPage {
? studydocument.title ? studydocument.title
: i18n('studydocs.name.default'); : i18n('studydocs.name.default');
if (studydocument._links.self.methods.includes('DELETE')) {
// User is allowed to delete this document
if (this.deleteDocument.id === studydocument._id && !this.deleteDocument.busy) {
actionButtons.push(
...[
m(Button, {
name: `delete-cancel-${studydocument._id}`,
className: 'flat-button',
label: i18n('studydocs.actions.cancel'),
events: {
onclick: () => {
this.deleteDocument = { id: null, busy: false };
},
},
}),
m(Button, {
name: `delete-confirm-${studydocument._id}`,
className: 'red-flat-button',
border: true,
label: i18n('studydocs.actions.confirm'),
events: {
onclick: async () => {
this.deleteDocument.busy = true;
try {
await StudydocsController.delete(studydocument._id, studydocument._etag);
controller.reload();
m.route.set(`/${currentLanguage()}/studydocuments`);
} catch (err) {
log.error(err);
this.deleteDocument = { id: null, busy: false };
}
},
},
}),
]
);
} else {
actionButtons.push(
m(Button, {
name: `delete-${studydocument._id}`,
className: 'blue-flat-button',
disabled: this.deleteDocument.id === studydocument._id && this.deleteDocument.busy,
label: i18n('studydocs.actions.delete'),
events: {
onclick: () => {
this.deleteDocument = { id: studydocument._id, busy: false };
},
},
})
);
}
}
const urlId = `studydoc-${studydocument._id}-url`; const urlId = `studydoc-${studydocument._id}-url`;
return m(ExpansionPanel, { return m(ExpansionPanel, {
...@@ -331,6 +387,7 @@ export default class StudydocList extends FilteredListPage { ...@@ -331,6 +387,7 @@ export default class StudydocList extends FilteredListPage {
), ),
m(ActionBar, { m(ActionBar, {
className: 'studydoc-actions', className: 'studydoc-actions',
left: actionButtons,
right: [ right: [
m('textarea', { m('textarea', {
id: urlId, id: urlId,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment