blob: af8e6cb21da056734ecf5c0b55f4d9f58002702d [file] [log] [blame]
Matteo Scandolod7552052016-03-11 13:47:27 -08001'use strict';
2
3angular.module('xos.truckroll', [
4 'ngResource',
5 'ngCookies',
6 'ngLodash',
7 'ui.router',
8 'xos.helpers'
9])
10.config(($stateProvider) => {
11 $stateProvider
12 .state('user-list', {
13 url: '/',
14 template: '<truckroll></truckroll>'
15 });
16})
17.config(function($httpProvider){
18 $httpProvider.interceptors.push('NoHyperlinks');
19})
20.service('Subscribers', function($resource){
21 return $resource('/xos/subscribers/:id');
22})
23.service('Truckroll', function($resource){
24 return $resource('/xoslib/truckroll/:id');
25})
26.directive('truckroll', function(){
27 return {
28 restrict: 'E',
29 scope: {},
30 bindToController: true,
31 controllerAs: 'vm',
32 templateUrl: 'templates/truckroll.tpl.html',
33 controller: function($timeout, Subscribers, Truckroll){
34 Subscribers.query().$promise
35 .then((subscribers) => {
36 this.subscribers = subscribers;
37 });
38
39 this.loader = false;
40
41 this.runTest = () => {
42
43 // clean previous tests
44 delete this.truckroll.result;
45
46 const test = new Truckroll(this.truckroll);
47 this.loader = true;
48 test.$save()
49 .then((res) => {
50 this.waitForTest(res.id);
51 })
52 };
53
54 this.waitForTest = (id) => {
55 Truckroll.get({id: id}).$promise
56 .then((testResult) => {
57 if(testResult.is_synced){
58 this.truckroll = angular.copy(testResult);
59 Truckroll.delete({id: id});
60 this.loader = false;
61 }
62 else{
63 $timeout(() => {
64 this.waitForTest(id);
65 }, 2000)
66 }
67 })
68 };
69 }
70 };
71});