Skip to content

Commit

Permalink
References learning-layers/timeliner#74, mostly refactoring.
Browse files Browse the repository at this point in the history
Refactored finding items by id or index in storge by item, added central
methods to be used everywhere. Also added the method to scroll timeline
to the item, if exists (used by stream).
  • Loading branch information
pjotrsavitski committed Oct 4, 2016
1 parent 3a2c9cd commit 37587f4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 26 deletions.
81 changes: 55 additions & 26 deletions app/scripts/controllers/project-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,58 +24,82 @@ angular.module('timelinerApp')
$scope.project = project;
ProjectsService.setCurrentProject(project);

function findAnnotationIndex(annotation) {
return _($scope.projectTimelineData.annotations).findIndex(function(o) {
return o._id === annotation._id;
function getDataSourceByItemType(type) {
var source;

switch(type) {
case 'annotation':
source = $scope.projectTimelineData.annotations;
break;
case 'milestone':
source = $scope.projectTimelineData.milestones;
break;
case 'task':
source = $scope.projectTimelineData.tasks;
break;
case 'resource':
source = $scope.projectTimelineData.resouces;
break;
case 'outcome':
source = $scope.projectTimelineData.outcomes;
break;
default:
throw 'Unknown object type';
}

return source;
}

function findItemIndex(type, item) {
var source = getDataSourceByItemType(type);

return _(source).findIndex(function(o) {
return o._id === item._id;
});
}

function findAnnotationById(id) {
return _($scope.projectTimelineData.annotations).find(function(o) {
function findItemById(type, id) {
var source = getDataSourceByItemType(type);

return _(source).find(function(o) {
return o._id === id;
});
}

function findAnnotationIndex(annotation) {
return findItemIndex('annotation', annotation);
}

function findAnnotationById(id) {
return findItemById('annotation', id);
}

function findMilestoneIndex(milestone) {
return _($scope.projectTimelineData.milestones).findIndex(function(o) {
return o._id === milestone._id;
});
return findItemIndex('milestone', milestone);
}

function findMilestoneById(id) {
return _($scope.projectTimelineData.milestones).find(function(o){
return o._id === id;
});
return findItemById('milestone', id);
}

function findTaskIndex(task) {
return _($scope.projectTimelineData.tasks).findIndex(function(o) {
return o._id === task._id;
});
return findItemIndex('task', task);
}

function findTaskById(id) {
return _($scope.projectTimelineData.tasks).find(function(o) {
return o._id === id;
});
return findItemById('task', id);
}

function findResourceIndex(resource) {
return _($scope.resources).findIndex(function(o) {
return o._id === resource._id;
});
return findItemIndex('resource', resource);
}

function findOutcomeIndex(outcome) {
return _($scope.projectTimelineData.outcomes).findIndex(function(o) {
return o._id === outcome._id;
});
return findItemIndex('outcome', outcome);
}

function findOutcomeById(id) {
return _($scope.projectTimelineData.outcomes).find(function(o) {
return o._id === id;
});
return findItemById('outcome', id);
}

function socketConnectCallback() {
Expand Down Expand Up @@ -467,6 +491,11 @@ angular.module('timelinerApp')
$scope.$broadcast('tl:timeline:fit_to_screen', ev);
};

$scope.showOnTimeline = function(ev, activity) {
$log.debug(ev, activity);
throw 'Not implemented';
};

$scope.resetPanels = function(ev) {
$log.error('Not implemented', ev);
};
Expand Down
1 change: 1 addition & 0 deletions app/views/project-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ <h3 translate translate-values="{{ ::getMessageTranslateValues(message) }}">STRE
<h3>{{ ::activity.created | tlDate : true }}</h3>
<p translate translate-values="{{ ::getActivityTranslateValues(activity) }}">{{ ::getActivityTranslateTemplate(activity) }}</p>
</div>
<md-icon class="md-secondary" md-font-set="mdi" md-font-icon="mdi-target" ng-click="showOnTimeline($event, activity)" aria-label="Show on Timeline"></md-icon>
<md-divider></md-divider>
</md-list-item>
</md-list>
Expand Down

0 comments on commit 37587f4

Please sign in to comment.