recent activities via API (#761)

This commit is contained in:
Kevin Papst
2019-05-07 22:24:28 +02:00
committed by GitHub
parent 98f386dad6
commit b1855447b8
40 changed files with 376 additions and 258 deletions

View File

@@ -32,7 +32,6 @@ export default class KimaiAjaxModalForm extends KimaiClickHandlerReducedInTableR
self._openFormInModal(html);
},
error: function(xhr, err) {
console.log('Failed opening modal', err);
window.location = href;
}
});
@@ -102,8 +101,12 @@ export default class KimaiAjaxModalForm extends KimaiClickHandlerReducedInTableR
// click handler for modal save button, to send forms via ajax
form.on('submit', function(event){
let btn = jQuery(formIdentifier + ' button[type=submit]').button('loading');
let eventName = form.attr('data-form-event');
let events = self.getContainer().getPlugin('event');
event.preventDefault();
event.stopPropagation();
jQuery.ajax({
url: form.attr('action'),
type: form.attr('method'),
@@ -117,14 +120,13 @@ export default class KimaiAjaxModalForm extends KimaiClickHandlerReducedInTableR
if (hasFieldError || hasFormError || hasFlashError) {
self._openFormInModal(html);
} else {
events.trigger(eventName);
self.getContainer().getPlugin('datatable').reload();
remoteModal.modal('hide');
}
return false;
},
error: function(xhr, err) {
console.log('Failed submitting modal form', err);
// FIXME problem in google and 500 error, keeps on submitting...
// what else could we do? submitting again at least gives us the opportunity to see errors,
// which maybe would be hidden otherwise... this one is totally up for discussion!

View File

@@ -18,13 +18,6 @@ export default class KimaiDatatable extends KimaiPlugin {
return 'datatable';
}
init() {
const self = this;
document.addEventListener('KimaiDatatableRequestReload', function() {
self.reload();
});
}
reload() {
let form = jQuery('.toolbar form');
let loading = '<div class="overlay"><i class="fas fa-sync fa-spin"></i></div>';

View File

@@ -83,7 +83,6 @@ export default class KimaiDatatableColumnView extends KimaiPlugin {
}
if (!foundColumn) {
console.error('Could not find column: ' + columnName);
return;
}

View File

@@ -0,0 +1,28 @@
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*!
* [KIMAI] KimaiEvent: helper to trigger events
*/
import KimaiPlugin from "../KimaiPlugin";
export default class KimaiEvent extends KimaiPlugin {
getId() {
return 'event';
}
trigger(name) {
if (name === null) {
return;
}
document.dispatchEvent(new Event(name));
}
}

View File

@@ -0,0 +1,81 @@
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*!
* [KIMAI] KimaiRecentActivities: responsible to reload the users recent activities
*/
import KimaiPlugin from '../KimaiPlugin';
export default class KimaiRecentActivities extends KimaiPlugin {
constructor(selector) {
super();
this.selector = selector;
}
getId() {
return 'recent-activities';
}
init() {
const menu = document.querySelector(this.selector);
// the menu can be hidden if user has no permissions to see it
if (menu === null) {
return;
}
const dropdown = menu.querySelector('ul.dropdown-menu');
this.attributes = dropdown.dataset;
this.itemList = dropdown.querySelector('li > ul.menu');
const self = this;
const handle = function() { self.reload(); };
// don't block initial browser rendering
setTimeout(handle, 500);
document.addEventListener('kimai.activityUpdate', handle);
document.addEventListener('kimai.projectUpdate', handle);
document.addEventListener('kimai.customerUpdate', handle);
}
emptyList() {
this.itemList.innerHTML = '';
}
setEntries(entries) {
if (entries.length === 0) {
this.emptyList();
return;
}
let htmlToInsert = '';
for (let timesheet of entries) {
let label = this.attributes['template']
.replace('%customer%', timesheet.project.customer.name)
.replace('%project%', timesheet.project.name)
.replace('%activity%', timesheet.activity.name);
htmlToInsert += `<li><a href="${ this.attributes['url'].replace('000', timesheet.id) }"><i class="${ this.attributes['icon'] }"></i> ${ label }</a></li>`;
}
this.itemList.innerHTML = htmlToInsert;
}
reload() {
const self = this;
const apiService = this.getContainer().getPlugin('api');
apiService.get(this.attributes['api'], function(result) {
self.setEntries(result);
});
}
}