app.controller('ExactQueueTasksCtrl', function($scope, $http, $route) { $scope.crons_table = { name: 'Cron status', controller: 'cron', showRowCount: false, showStatistics: false, listUndefinedFields: false, panelClass: 'panel-trainingskampen', fields: ['name', 'cron_running', 'cron_emergency_stop', 'cron_heartbeat', 'maintenance_till'], fieldDetails: { 'id': { hideList: true }, 'organization_id': { hideList: true }, 'debug': { type: 'boolean', label: 'Debug', hideList: true, booleanOn: '1', booleanOff: '0' }, 'version': { type: 'text', label: 'Versie', hideList: true }, 'name': { type: 'text', label: 'Naam' }, 'cron_running': { type: 'boolean', label: 'Actief', booleanOn: '1', booleanOff: '0' }, 'cron_emergency_stop': { type: 'boolean', label: 'Noodstop', booleanOn: '1', booleanOff: '0' }, 'cron_heartbeat': { type: 'datetime', label: 'Heartbeat' }, 'maintenance_till': { type: 'datetime', label: 'Onderhoud tot' }, }, buttons: { 'C': { id: 'c', header: false }, 'R': { id: 'r', inline: false }, 'DETAILS': { id: 'details_cron', name: 'Details', label: 'Details', inline: true, header: false, icon: 'fa-eye', action: 'viewCronRow', parentScope: true, }, 'U': { id: 'u', inline: false }, 'D': { id: 'd', inline: false }, }, }; $scope.viewCronRow = function(btn, row, blnSubmit) { $scope.selectedCron = row; $('#cronDetailModal').modal('show'); }; $scope.formatVersion = function(v) { if (!v || String(v).length !== 14) { return v; } v = String(v); return v.substr(0, 4) + '-' + v.substr(4, 2) + '-' + v.substr(6, 2) + ' ' + v.substr(8, 2) + ':' + v.substr(10, 2) + ':' + v.substr(12, 2); }; $scope.parseJson = function(str) { if (!str) { return {}; } try { return JSON.parse(str); } catch(e) { return { raw: str }; } }; $scope.formatKey = function(key) { return key.replace(/_/g, ' ').replace(/\b\w/g, function(c) { return c.toUpperCase(); }); }; $scope.exact_queue_tasks_table = { name: 'Exact Taken', controller: 'exact_queue_task', showRowCount: true, showStatistics: false, listUndefinedFields: false, panelClass: 'panel-trainingskampen', subQueries: { 'exact_statuses': { 'lfield': 'status_id', 'ffield': 'id', 'controller': 'exact_status', }, }, fields: ['function', 'invoice_id', 'status_id', 'done', 'error', 'created_at', 'updated_at'], fieldDetails: { 'id': { label: 'ID', type: 'number', hideList: true }, 'function': { label: 'Task' }, 'invoice_id': { label: 'Invoice ID', type: 'number' }, 'status_id': { label: 'Status', changeTo: ['exact_statuses.id', ' - ', 'exact_statuses.name'] }, 'error_message': { label: 'Error message', hideList: true }, 'done': { label: 'Done', type: 'boolean', booleanOn: '1', booleanOff: '0' }, 'error': { label: 'Error', type: 'boolean', booleanOn: '1', booleanOff: '0' }, 'created_at': { label: 'Created', type: 'datetime', sortAsc: false }, 'updated_at': { label: 'Updated', type: 'datetime' }, 'data': { label: 'Data', hideList: true }, 'can_redo': { hideList: true, hideEdit: true }, 'started': { hideList: true }, 'deleted_at': { hideList: true, hideEdit: true }, }, buttons: { 'C': { id: 'c', header: false }, 'R': { id: 'r', inline: false }, 'DETAILS': { id: 'details_task', name: 'Details', label: 'Details', inline: true, header: false, icon: 'fa-eye', action: 'viewTaskRow', parentScope: true, }, 'REDO': { id: 'redo_task', name: 'Opnieuw', label: 'Opnieuw', inline: true, header: false, noFields: true, icon: 'fa-redo', action: 'redoTask', parentScope: true, whereField: 'can_redo', where: { '==': 1 }, }, 'U': { id: 'u', inline: false }, 'D': { id: 'd', inline: false }, }, }; $scope.exactStatusNames = { 1: 'Wachtrij', 3: 'Bezig', 4: 'Mislukt', 5: 'Voltooid', 6: 'Overgeslagen', 7: 'Hersteld', }; $scope.viewTaskRow = function(btn, row, blnSubmit) { $scope.selectedTask = row; $('#taskDetailModal').modal('show'); }; $scope.redoTask = function(btn, row, blnSubmit) { if (row.can_redo != 1) { return; } $http.post('/exact_queue_task/redo/' + row.id).then(function(response) { delete btn.loading; if (response.data && response.data.status) { $route.reload(); } }, function(error) { delete btn.loading; console.error('Redo failed', error); }); }; });