Skip to content

Commit

Permalink
Add statring/stopping of task from tray
Browse files Browse the repository at this point in the history
  • Loading branch information
Maigo Erit committed Apr 26, 2016
1 parent 20c4b13 commit ca080d0
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 289 deletions.
19 changes: 10 additions & 9 deletions app/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ var config = require('./config')
* Docs:
* https://github.com/maxogden/menubar
*/
var mb = menubar({
dir: path.join(config.pluginsPath, 'tray'),
icon: path.join(config.root, 'shared/img/icon/timetracker_icon.png'),
preloadWindow: true,
width: 300,
height: 400,
showDock: true
var mb = menubar({
dir: path.join(config.pluginsPath, 'tray'),
icon: path.join(config.root, 'shared/img/icon/timetracker_icon.png'),
preloadWindow: true,
width: 300,
height: 400,
showDock: true
})

mb.on('after-create-window', function () {
//mb.window.openDevTools();
//mb.window.openDevTools();
});
mb.on('ready', function () {})
mb.on('ready', function () {
})

module.exports = mb
64 changes: 63 additions & 1 deletion plugins/tray/app/trackItem/trackItem.list.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,68 @@


angular.module('trayApp')
.controller('TrackItemListController', function (TrackItemService, $rootScope) {
.controller('TrackItemListController', function (TrackItemService, $rootScope, $scope) {
var ctrl = this;
ctrl.trackItems = [];

var today = moment().startOf('day');

ctrl.loading = false;
ctrl.list = function () {
console.log("Refresh data");

ctrl.loading = true;
TrackItemService.findAll({
limit: 10,
orderBy: [
['beginDate', 'DESC']
], where: {
taskName: {
'==': 'LogTrackItem'
}
}
}).then(function (items) {
ctrl.trackItems = items;
ctrl.loading = false;
items.forEach(function (item) {
item.timeDiffInMs = moment(item.endDate).diff(item.beginDate);
item.duration = moment.duration(item.endDate - item.beginDate);
});
$rootScope.$apply();
});
};


ctrl.startNewLogItem = function (oldItem) {
console.log("startNewLogItem");

var newItem = {};
newItem.app = "Default";
newItem.taskName = "LogTrackItem";
newItem.color = oldItem.color;
newItem.title = oldItem.title;
newItem.beginDate = moment().toDate();
newItem.endDate = moment().add(60, 'seconds').toDate();

TrackItemService.create(newItem).then(function (item) {
console.log("Created newItem to DB:", item);

//$scope.$broadcast('addItemToTimeline', item);
ctrl.runningLogItem = item;
$scope.$apply();
});
};

ctrl.stopRunningLogItem = function () {
console.log("startNewLogItem");

TrackItemService.update(ctrl.runningLogItem.id, {endDate: new Date()}).then(function (item) {
console.log("Updated trackitem to DB:", item);

ctrl.runningLogItem = null;
$scope.$apply();
});
};

ctrl.list();
});
37 changes: 37 additions & 0 deletions plugins/tray/app/trackItem/trackItem.list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<md-content>
<md-list flex>
<md-list-item ng-if="trackItemCtrl.runningLogItem" class="tray-item" ng-click="null">
<div class="md-list-item-text">
<h3>{{trackItemCtrl.runningLogItem.title}}</h3>

<p>{{trackItemCtrl.runningLogItem.beginDate | date: 'yyyy.MM.dd HH:mm'}} -
{{trackItemCtrl.runningLogItem.endDate | date: 'yyyy.MM.dd HH:mm'}}</p>
</div>
<md-button class="md-secondary md-icon-button" ng-click="trackItemCtrl.stopRunningLogItem()" aria-label="stop task">
<md-tooltip md-direction="left">
Stop task
</md-tooltip>
<md-icon md-font-set="material-icons">stop</md-icon>
</md-button>
</md-list-item>
<md-list-item ng-if="!trackItemCtrl.runningLogItem" class="tray-item" ng-click="null">
<div class="md-list-item-text">
<h3>No running tasks</h3>
</div>
</md-list-item>
<md-subheader class="md-no-sticky">Last tasks</md-subheader>
<md-list-item class="tray-item" ng-repeat="item in trackItemCtrl.trackItems" ng-click="null">
<div class="md-list-item-text">
<h3>{{item.title}}</h3>

<p>{{item.beginDate | date: 'yyyy.MM.dd HH:mm'}} - {{item.endDate | date: 'yyyy.MM.dd HH:mm'}}</p>
</div>
<md-button class="md-secondary md-icon-button" ng-click="trackItemCtrl.startNewLogItem(item)" aria-label="start task">
<md-tooltip md-direction="left">
Start task
</md-tooltip>
<md-icon md-font-set="material-icons">play_circle_filled</md-icon>
</md-button>
</md-list-item>
</md-list>
</md-content>
2 changes: 1 addition & 1 deletion plugins/tray/app/trackItem/trackItem.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ angular.module('trayApp.trackItem')
.state('app.trackItem', {
url: '/trackItem',
abstract: true,
template: '<div ui-view="page" class="fade-in-up"></div>'
template: '<div ui-view="page"></div>'
})
.state('app.trackItem.list', {
url: '/list?search',
Expand Down
4 changes: 2 additions & 2 deletions plugins/tray/app/trackItem/trackItem.service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
angular.module('trayApp')
.service('TrackItemService', function () {

return require('remote').getGlobal('trackItemServiceInst');
var service = require('remote').getGlobal('BackgroundService').getTrackItemService();
return service;
});
Loading

0 comments on commit ca080d0

Please sign in to comment.