Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve digest cycle #486

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions js/app/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ import md from 'angular-markdown-it';
import markdownitLinkTarget from 'markdown-it-link-target';
import markdownitCheckbox from 'legacy/markdown-it-checkbox.js';

app.config(function ($provide, $interpolateProvider, $httpProvider, $urlRouterProvider, $stateProvider, $compileProvider, markdownItConverterProvider) {
app.config(function ($provide, $interpolateProvider, $httpProvider, $urlRouterProvider, $stateProvider, $compileProvider, markdownItConverterProvider, $logProvider) {
'use strict';
$httpProvider.defaults.headers.common.requesttoken = oc_requesttoken;


$compileProvider.debugInfoEnabled(true);

markdownItConverterProvider.use(markdownitLinkTarget, {
Expand Down
31 changes: 22 additions & 9 deletions js/controller/BoardController.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,18 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St
if ($scope.stacks === undefined) {
return;
}
angular.copy(StackService.getData(), $scope.stacks);
$scope.stacks = $filter('orderBy')($scope.stacks, 'order');
angular.forEach($scope.stacks, function (value, key) {
var cards = $filter('cardSearchFilter')(value.cards, text);
cards = $filter('orderBy')(cards, order);
$scope.stacks[key].cards = cards;
});
$scope.stacks = StackService.getData();
$scope.stacks = $filter('orderBy')($scope.stacks, order);
/* only copy the whole stacks to local scope for filtering them while searching */
console.log(text);
if (text !== '') {
angular.copy(StackService.getData(), $scope.stacks);
angular.forEach($scope.stacks, function (value, key) {
var cards = $filter('cardSearchFilter')(value.cards, text);
cards = $filter('orderBy')(cards, order);
$scope.stacks[key].cards = cards;
});
}
};

$scope.loadDefault = function () {
Expand Down Expand Up @@ -266,12 +271,20 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St
card.stackId = newStack;
CardService.update(card);
CardService.reorder(card, order).then(function (data) {
StackService.addCard(card);
StackService.reorderCard(card, order);
// not working ? https://www.aaron-gray.com/delaying-the-digest-cycle-in-angularjs/
// we want the digest to happen after all sorting operations are complete
var watchers = $scope.$$watchers;
StackService.$$watchers = [];
StackService.removeCard({
id: card.id,
stackId: oldStack
});
StackService.addCard(card);
StackService.reorderCard(card, order);
// restore watchers and run digest now
if (watchers)
StackService.$$watchers = watchers;
$scope.$digest();
});
},
orderChanged: function (event) {
Expand Down
8 changes: 4 additions & 4 deletions js/controller/CardController.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ app.controller('CardController', function ($scope, $rootScope, $sce, $location,
var currentTime = Date.now();
var timeSinceEdit = currentTime-$scope.status.lastEdit;
if (timeSinceEdit > 1000 && $scope.status.lastEdit > $scope.status.lastSave && !$scope.status.saving) {
$scope.status.lastSave = currentTime;
$scope.status.lastSave = $scope.status.lastEdit = currentTime;
$scope.status.saving = true;
var header = $('.section-header.card-description');
header.find('.save-indicator.unsaved').fadeIn(500);
CardService.update($scope.status.edit).then(function (data) {
var header = $('.section-header.card-description');
header.find('.save-indicator.unsaved').hide();
header.find('.save-indicator.saved').fadeIn(250).fadeOut(1000);
StackService.updateCard($scope.status.edit);
//StackService.updateCard($scope.status.edit);
$scope.status.saving = false;
});
}
Expand Down Expand Up @@ -216,14 +216,14 @@ app.controller('CardController', function ($scope, $rootScope, $sce, $location,

$scope.addAssignedUser = function(item) {
CardService.assignUser(CardService.getCurrent(), item.uid).then(function (data) {
StackService.updateCard(CardService.getCurrent());
//StackService.updateCard(CardService.getCurrent());
});
$scope.status.showAssignUser = false;
};

$scope.removeAssignedUser = function(uid) {
CardService.unassignUser(CardService.getCurrent(), uid).then(function (data) {
StackService.updateCard(CardService.getCurrent());
//StackService.updateCard(CardService.getCurrent());
});
};

Expand Down
5 changes: 5 additions & 0 deletions js/service/ApiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,17 @@ app.factory('ApiService', function ($http, $q) {
angular.forEach(entities, function (entity) {
self.add(entity);
});
console.log(self);
};

ApiService.prototype.getCurrent = function () {
return this.data[this.id];
};

ApiService.prototype.get = function (id) {
return this.data[id];
};

ApiService.prototype.unsetCurrrent = function () {
this.id = null;
};
Expand Down
11 changes: 10 additions & 1 deletion js/service/StackService.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
import app from '../app/App.js';

app.factory('StackService', function (ApiService, $http, $q) {
app.factory('StackService', function (ApiService, $http, $q, CardService) {
var StackService = function ($http, ep, $q) {
ApiService.call(this, $http, ep, $q);
};
Expand All @@ -32,6 +32,12 @@ app.factory('StackService', function (ApiService, $http, $q) {
$http.get(this.baseUrl + '/' + boardId).then(function (response) {
self.clear();
self.addAll(response.data);
// When loading a stack add cards to the CardService so we can fetch
// information from there. That way we don't need to refresh the whole
// stack data during digest if some value changes
angular.forEach(response.data, function (entity) {
CardService.addAll(entity.cards);
});
deferred.resolve(self.data);
}, function (error) {
deferred.reject('Error while loading stacks');
Expand All @@ -45,6 +51,9 @@ app.factory('StackService', function (ApiService, $http, $q) {
$http.get(this.baseUrl + '/' + boardId + '/archived').then(function (response) {
self.clear();
self.addAll(response.data);
angular.forEach(response.data, function (entity) {
CardService.addAll(entity.cards);
});
deferred.resolve(self.data);
}, function (error) {
deferred.reject('Error while loading stacks');
Expand Down
7 changes: 6 additions & 1 deletion js/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ module.exports = {
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
})
}),
new webpack.DefinePlugin({
'process.env': {
DEBUG: true,
}
}),
]
};
6 changes: 3 additions & 3 deletions templates/part.board.mainView.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</h3>
<ul data-as-sortable="sortOptions" is-disabled="!boardservice.canEdit() || filter==='archive'" data-ng-model="s.cards" class="card-list" ng-class="{emptyStack: !s.cards.length}">
<li class="card as-sortable-item"
ng-repeat="c in s.cards"
ng-repeat="c in s.cards track by c.id"
data-as-sortable-item
ng-click="$event.stopPropagation()"
ui-sref="board.card({boardId: id, cardId: c.id})"
Expand All @@ -75,7 +75,7 @@
</div>

<div class="card-controls">
<i class="icon icon-filetype-text" ng-if="c.description" title="{{ c.description }}"></i>
<i class="icon icon-filetype-text" ng-if="cardservice.get(c.id).description" title="{{ cardservice.get(c.id).description }}"></i>
<span class="due" ng-if="c.duedate" ng-class="{'overdue': c.overdue == 3, 'now': c.overdue == 2, 'next': c.overdue == 1 }" title="{{ c.duedate }}">
<i class="icon icon-badge"></i>
<span data-timestamp="{{ c.duedate | dateToTimestamp }}" class="live-relative-timestamp">{{ c.duedate | relativeDateFilterString }}</span>
Expand All @@ -85,7 +85,7 @@
<span>{{ getCheckboxes(c.description)[0] }}/{{ getCheckboxes(c.description)[1] }}</span>
</div>
<div class="card-assigned-users">
<div class="assigned-user" ng-repeat="user in c.assignedUsers | limitTo: 3">
<div class="assigned-user" ng-repeat="user in cardservice.get(c.id).assignedUsers | limitTo: 3">
<avatar data-user="{{ user.participant.uid }}" data-displayname="{{ user.participant.displayname }}" data-tooltip></avatar>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/part.card.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<div class="section-content card-description">
<textarea elastic ng-if="status.cardEditDescription"
placeholder="<?php p($l->t('Add a card description…')); ?>"
ng-blur="cardUpdate(status.edit)"
ng-blur="cardUpdate(status.edit); updateMarkdown(status.edit.description)"
ng-model="status.edit.description"
ng-change="cardEditDescriptionChanged(); updateMarkdown(status.edit.description)"
autofocus-on-insert> </textarea>
Expand Down