(function () { "use strict"; var streamApp = angular.module('streamApp'); streamApp.directive('timelinesDirective', ['timelineService', 'sharingService', '$location', TimelinesDirective]); function TimelinesDirective(timelineService, sharingService, $location) { return { restrict: 'E', scope: { prompt: '=', refresh: '=' }, templateUrl: '/App/Directives/timelines/timelinesDirective/timelinesDirective.html?v=6.0.0c', link: function (scope, element, attrs, tabsCtrl) { scope.refresh = function () { timelineService.getAll().then((timelines) => { console.log('time ', timelines); scope.timelines = timelines.map(t => { return { name: t.name, description: t.description, id: t.id, active: t.active, creator: t.creator }; }) scope.yourTimelines = scope.timelines.filter(x => x.creator); scope.sharedTimelines = scope.timelines.filter(x => !x.creator); }); } scope.refresh(); sharingService.getContacts().then(function (data) { scope.hasConnections = data.data && data.data.length; }); scope.edit = function (timeline) { timeline.editing = true; timeline.tempName = timeline.name; timeline.tempDescription = timeline.description; } scope.save = function (timeline) { timelineService.update( timeline.id, timeline.tempName, timeline.tempDescription).then(result => { timeline.name = result.name; timeline.description = result.description; scope.cancel(timeline); }); } scope.cancel = function (timeline) { timeline.editing = false; timeline.tempName = ''; timeline.tempDirection = ''; } scope.follow = function (timeline) { if (timeline.active) { timelineService.unfollow(timeline.id).then(() => timeline.active = false ); } else { timelineService.follow(timeline.id).then(() => timeline.active = true ); } } scope.inviteCallback = (timeline) => { if (scope.hasConnections) { $location.url(`timelines/${timeline.id}/invitations?edit=true`); } else { $location.url(`sharing`); } } } }; } }());