add nifty short syntax

This commit is contained in:
Johannes Millan 2017-01-12 21:45:21 +01:00
parent e9c26b8264
commit 2cc4de55a6
8 changed files with 75 additions and 17 deletions

View file

@ -129,7 +129,9 @@ TODO configure more restrictive Content-Security-Policy
<script src="scripts/main/global-services/git-log-s.js"></script>
<script src="scripts/main/global-services/jira-s.js"></script>
<script src="scripts/main/global-services/notifier-s.js"></script>
<script src="scripts/main/global-services/parse-duration-s.js"></script>
<script src="scripts/main/global-services/projects-s.js"></script>
<script src="scripts/main/global-services/short-syntax-s.js"></script>
<script src="scripts/main/global-services/simple-toast-s.js"></script>
<script src="scripts/main/global-services/tasks-s.js"></script>
<script src="scripts/main/global-services/uid-s.js"></script>

View file

@ -45,6 +45,9 @@
git: {
projectDir: undefined
},
config: {
isShortSyntaxEnabled: true
},
jiraSettings: {
isFirstLogin: true,
defaultTransitionInProgress: undefined,

View file

@ -0,0 +1,34 @@
/**
* @ngdoc service
* @name superProductivity.ShortSyntax
* @description
* # ShortSyntax
* Service in the superProductivity.
*/
(function () {
'use strict';
angular
.module('superProductivity')
.service('ShortSyntax', ShortSyntax);
/* @ngInject */
function ShortSyntax(ParseDuration) {
const timeEstimateRegExp = / t[0-9]+(m|h|d)$/i;
return (task) => {
if (!task.originalKey && !task.timeEstimate && !task.subTasks) {
let matches = timeEstimateRegExp.exec(task.title);
if (matches) {
task.timeEstimate = ParseDuration.fromString(matches[0].replace(' t', ''));
task.title = task.title.replace(matches[0], '');
}
}
return task;
};
}
})
();

View file

@ -0,0 +1,17 @@
'use strict';
describe('Service: ShortSyntax', function () {
// load the service's module
beforeEach(module('superProductivity'));
// instantiate service
var ShortSyntax;
beforeEach(inject(function (_ShortSyntax_) {
ShortSyntax = _ShortSyntax_;
}));
it('should be defined', function () {
expect(true).toBe(true);
});
});

View file

@ -14,7 +14,7 @@
.service('Tasks', Tasks);
/* @ngInject */
function Tasks($localStorage, Uid, $window, $rootScope, Dialogs, IS_ELECTRON, SimpleToast) {
function Tasks($localStorage, Uid, $window, $rootScope, Dialogs, IS_ELECTRON, SimpleToast, ShortSyntax) {
const IPC_EVENT_IDLE = 'WAS_IDLE';
const IPC_EVENT_UPDATE_TIME_SPEND_FOR_CURRENT = 'UPDATE_TIME_SPEND';
const IPC_EVENT_CURRENT_TASK_UPDATED = 'CHANGED_CURRENT_TASK';
@ -282,7 +282,7 @@
};
this.createTask = (task) => {
return {
let transformedTask = {
title: task.title,
id: Uid(),
created: moment(),
@ -301,6 +301,7 @@
originalComments: task.originalComments,
originalUpdated: task.originalUpdated
};
return ShortSyntax(transformedTask);
};
this.updateToday = (tasks) => {

View file

@ -200,20 +200,17 @@
Import Settings
</md-button>
<form ng-if="vm.showUploadForm"
ng-submit="vm.importSettings(vm.uploadSettingsTextarea)">
<section>
<h2 class="md-title">Misc</h2>
<md-input-container class="md-block"
flex-gt-sm>
<label>Copy and paste the contents of the download json file here</label>
<textarea ng-model="vm.uploadSettingsTextarea"
md-auto-focus
rows="3"></textarea>
<div flex-gt-sm="50">
<md-checkbox ng-model="vm.isDarkTheme"
aria-label="Use dark theme">
Use short syntax (e.g. 'TaskTitleBla e:30m')
</md-checkbox>
</div>
</md-input-container>
<md-button type="submit"
class="md-raised md-primary">Import settings
</md-button>
</form>
<md-divider></md-divider>
</section>
</section>
</div>

View file

@ -50,7 +50,7 @@
<span class="text"
tabindex="2"
edit-on-click-on-edit-finished="vm.focusLastFocusedTaskEl()"
edit-on-click-on-edit-finished="vm.focusLastFocusedTaskEl(); vm.onChangeTitle(task);"
edit-on-click-ev-id="{{ task.id }}"
edit-on-click="task.title">{{ task.title }}</span>
</div>

View file

@ -37,7 +37,7 @@
}
/* @ngInject */
function TaskListCtrl(Dialogs, $mdToast, $timeout, $window, Tasks, EDIT_ON_CLICK_TOGGLE_EV, $scope) {
function TaskListCtrl(Dialogs, $mdToast, $timeout, $window, Tasks, EDIT_ON_CLICK_TOGGLE_EV, $scope, ShortSyntax) {
let vm = this;
let lastFocusedTaskEl;
@ -124,6 +124,10 @@
}
};
vm.onChangeTitle = (task) => {
ShortSyntax(task);
};
vm.handleKeyPress = ($event, task, $index) => {
let taskEl = $event.currentTarget || $event.srcElement || $event.originalTarget;
lastFocusedTaskEl = taskEl;