This repository has been archived by the owner on Dec 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapp.js
212 lines (200 loc) · 8.94 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
* Software License Agreement (Apache License)
*
* Copyright (c) 2016, PPM AS
* Contact: [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
angular.module("flexGuiApp", ["ngCookies", "ngRoute", 'ngSanitize', "ui.bootstrap-slider", "perfect_scrollbar", "jg.knob", "hmTouchEvents", "ngCordova", "angularStats", "ui.router", "oc.lazyLoad"])
angular.module("flexGuiApp", ["ngCookies", "ngRoute", 'ngSanitize', "ui.bootstrap-slider", "perfect_scrollbar", "jg.knob", "hmTouchEvents", "angularStats", "ui.router"])
.directive("ngFileSelect", ngFileSelect)
.directive("fgFidgetRepeater", function () {
var directive = {
restrict: 'AEC',
template: function (elm, attr) {
return "<div class='fidget {{fidget.properties.name}}' ng-if='fidget.template' id='{{fidget.id}}' ng-repeat='fidget in " + attr.fidgets + " track by fidget.id' ng-class=\"{'notSelectable': editHandler.selectableFidgets != null && editHandler.selectableFidgets.indexOf(fidget.id) == -1, 'editModeOn': editHandler.isEditMode, 'selected': editHandler.selectedFidgets.indexOf(fidget) >= 0 }\" style=\"left:{{fidget.properties.left}}px; top: {{fidget.properties.top}}px;\">" +
"<div ng-class=\"{'disabled': [false, 'false', 0].indexOf(fidget.properties.enabled) != -1 ,'clickable': !editHandler.isEditMode && [undefined, 'undefined', '', null, 'null'].indexOf(fidget.properties.onClick) == -1, 'selectedFidget': editHandler.selectedFidgets.indexOf(fidget) > -1 && editHandler.isEditMode, 'dragged': editHandler.selectedFidgets.length > 0 && editHandler.isMouseDown && !editHandler.inResize && editHandler.selectedFidgets.indexOf(fidget) > -1 }\">" +
"<ng-include ng-controller='fidgetCtrl' src=\"toTrustedUrl(fidget.template.root + fidget.template.source + '.html')\"></ng-include>" +
"</div>" +
"</div>";
},
};
return directive;
}).directive('scrollTopOnRefresh', function () {
return function (scope, element, attrs) {
if (scope.$last) {
setTimeout(function () {
//if the last element is loaded, scroll to the bottom of the message list
$(".scrollTop").each(function () {
$(this).scrollTop(0);
});
}, 500);
}
};
}).directive('scrollBottomOnRefresh', function () {
return function (scope, element, attrs) {
if (scope.$last) {
setTimeout(function () {
//if the last element is loaded, scroll to the bottom of the message list
$(".scrollBottom").each(function () {
$(this).scrollTop($(this).find(".scrollItems").prop('scrollHeight'));
});
}, 500);
}
};
}).directive('showPerfectScrollBar', function () {
return function (scope, element, attrs) {
setTimeout(function () {
$(".perfectScrollBar").each(function () {
$(this).perfectScrollbar('update');
});
}, 500);
};
}).directive('imageload', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
element.bind('load', function () {
//call the function that was passed
scope.$apply(attrs.imageload);
});
}
};
}).directive('imageerror', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
element.bind('error', function () {
//call the function that was passed
scope.$apply(attrs.imageerror);
});
}
};
}).directive('compile', ['$compile', function ($compile) {
return function (scope, element, attrs) {
scope.$watch(
function (scope) {
return scope.$eval(attrs.compile);
},
function (value) {
element.html(value);
$compile(element.contents())(scope);
}
)
};
}]).filter('isTopicFilter', function () {
return function (items, value) {
var filtered = [];
for (var i = 0; i < items.length; i++) {
var item = items[i];
var isTopic = item.isTopic || false;
if (isTopic === value) {
filtered.push(item);
}
}
return filtered;
};
}).filter('orderObjectBy', function () {
return function (items, field, reverse) {
var filtered = [];
angular.forEach(items, function (item) {
filtered.push(item);
});
filtered.sort(function (a, b) {
return (a[field] > b[field] ? 1 : -1);
});
if (reverse) filtered.reverse();
return filtered;
};
}).filter('stringSort', function () {
return function (input) {
return input.sort();
}
})
.controller('flexGuiCtrl', flexGuiCtrl)
.controller('propertiesWindowCtrl', propertiesWindowCtrl)
.controller('fidgetCtrl', fidgetCtrl)
.controller('fidgetGroupCtrl', fidgetGroupCtrl)
.factory('backgroundService', backgroundService)
.factory('editorService', editorService)
.factory('deviceService', deviceService)
.factory('imageService', imageService)
.factory('fidgetService', fidgetService)
.factory('projectService', projectService)
.factory('projectWindowService', projectWindowService)
.factory('historyService', historyService)
.factory('enumService', enumService)
.factory('variableService', variableService)
.factory('clipboardService', clipboardService)
.factory('settingsWindowService', settingsWindowService)
.factory('helpService', helpService)
.factory('popupService', popupService)
.factory('scriptManagerService', scriptManagerService)
.factory('colorPickerService', colorPickerService)
.factory('projectConversionService', projectConversionService)
.factory('projectStorageService', projectStorageService)
.factory('diagnosticsService', diagnosticsService)
.factory('backupService', backupService)
.factory('iconService', iconService)
.run(run);
ngFileSelect.$inject = ['$parse', 'projectWindowService'];
function ngFileSelect($parse, projectWindowService) {
var directiveDefinitionObject = {
restrict: 'A',
scope: {
method: '&ngFileSelect',
},
link: function (scope, element, attrs) {
var expressionHandler = scope.method();
element.bind('change', function (e) {
expressionHandler(e.target.files[0]);
});
}
};
return directiveDefinitionObject;
}
run.$inject = ['$rootScope', '$templateCache', '$location', '$timeout', 'settingsWindowService', 'projectService', 'variableService', 'deviceService', 'popupService'];
function run($rootScope, $templateCache, $location, $timeout, settingsWindowService, projectService, variableService, deviceService, popupService) {
if (!$rootScope.settingsTabs) $rootScope.settingsTabs = [];
$rootScope.mirrorMode = {};
$rootScope.currentUserId = "user_" + variableService.guid();
projectService.appVersion = "1.9.8";
//set ROS address with query string
var queryString = $location.search();
if (queryString && queryString.RosUrl) {
console.log("Using ROS server in the query string");
//get parameters from query string
var rosurl = queryString.RosUrl, ip, port, wss = false;
if (rosurl.indexOf("wss") === 0) {
wss = true;
ip = rosurl.substring(6, rosurl.lastIndexOf(":"));
} else {
ip = rosurl.substring(5, rosurl.lastIndexOf(":"));
}
port = rosurl.substring(rosurl.lastIndexOf(":") + 1);
//setup parameters
deviceService.port = port;
deviceService.ip = ip;
deviceService.secure = wss;
settingsWindowService.demoMode = false;
}
//location setup
$rootScope.startPage = $location.path().substring(1);
$rootScope.$on('$routeChangeStart', function (event, next, current) {
if (typeof (current) !== 'undefined') {
$templateCache.remove(current.templateUrl);
}
});
$(window).resize(function () { $rootScope.$apply(); });
}