-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
160 lines (159 loc) · 8.54 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
/* Data Analytics Toolkit: Explore any data avaialable through a REST service
* Copyright (C) 2016 Scott Aslan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/agpl.html>.
*/
define(['rndr-angular-module'],
function() {
var app = angular.module('sampleApp', ['ngResource', 'ngRoute', 'ngMaterial', 'ui.sortable', 'angular-contextMenu', 'ui.ace', 'ngRndr', 'ngRndr.templates'])
.config(function($locationProvider, $mdThemingProvider) {
$locationProvider.html5Mode(true);
//Define app palettes
var customBluePaletteMap = $mdThemingProvider.extendPalette("grey", {
"contrastDefaultColor": "light",
"contrastDarkColors": ["100"], //hues which contrast should be "dark" by default
"contrastLightColors": ["600"], //hues which contrast should be "light" by default
"500": "021b2c"
});
var customRedPaletteMap = $mdThemingProvider.extendPalette("grey", {
"contrastDefaultColor": "dark",
"contrastDarkColors": ["100"], //hues which contrast should be "dark" by default
"contrastLightColors": ["600"], //hues which contrast should be "light" by default
"500": "B22234"
});
$mdThemingProvider.definePalette("bluePalette", customBluePaletteMap);
$mdThemingProvider.definePalette("redPalette", customRedPaletteMap);
$mdThemingProvider.theme("default").primaryPalette("bluePalette", {
"default": "500",
"hue-1": "50", // use for the <code>md-hue-1</code> class
"hue-2": "300", // use for the <code>md-hue-2</code> class
"hue-3": "600" // use for the <code>md-hue-3</code> class
}).accentPalette("redPalette", {
"default": "500",
"hue-1": "50", // use for the <code>md-hue-1</code> class
"hue-2": "300", // use for the <code>md-hue-2</code> class
"hue-3": "600" // use for the <code>md-hue-3</code> class
});
}).controller('Controller', ['ServiceProvider', 'RenderingEngineManager', 'UiControls', 'DataSourceConfigurationManager', 'Renderers', '$window', '$rootScope', '$timeout', '$http', '$location', '$scope', function (ServiceProvider, RenderingEngineManager, UiControls, DataSourceConfigurationManager, Renderers, $window, $rootScope, $timeout, $http, $location, $scope) {
function Controller() {
this.mainContentView;
};
Controller.prototype = {
constructor: Controller,
init: function() {
//The Parallax jQuery plugin (sometimes) adds an extra
//body tag to the DOM if loaded in the <head></head> as
//RequireJs does
var extraBodyTag = document.getElementsByTagName('body')[1];
if(extraBodyTag !== undefined){
extraBodyTag.remove();
}
//resize mainContent on window resize
angular.element($window).bind('resize', function() {
//This is here to force the Explore and Dashboard Designer directives
//to re-link which will allow the gridster to draw itself to the appropriate
//size. The Data Aquisition Wizard however is a multi step work flow and is built
//in a responsive manner...so it resizes itself appropriately on window
//resize and thus we dont need or want to cause the directive to re-link since
//this will cause it to start over at step 1...
if (controller.mainContentView !== "Data Source Configuration Wizard") {
var view = controller.mainContentView;
controller.mainContentView = "Loading";
// $('body').scope().$apply();
controller.mainContentView = view;
}
});
$rootScope.$on('data source configuration wizard save', function() {
controller.initiateDataExploration(false);
});
$rootScope.$on('data source wizard configuration cancel', function() {
controller.mainContentView = '';
});
$rootScope.$on('initiate data source configuration wizard', function() {
controller.initiateDataSourceConfigurationWizard();
});
$rootScope.$on('Explore View', function() {
controller.initiateDataExploration();
$scope.$apply();
});
$rootScope.$on('draw initiated', function() {
UiControls.showRenderingEngineProgress();
});
$rootScope.$on('draw complete', function() {
UiControls.hideRenderingEngineProgress();
});
if($location.search().embedded === "true"){
controller.embedded = true;
controller.mainContentView = "Loading";
}
if($location.search().rdatasets === "true"){
//GET sample data
$http({method: 'GET', url: 'http://nicolas.kruchten.com/Rdatasets/datasets.csv'}).then(function successCallback(csvlist) {
// this callback will be called asynchronously
// when the response is available
var csvlist_arr = $.csv.toObjects(csvlist.data);
angular.forEach(csvlist_arr, function(dataset) {
var dataSourceConfigurationId = DataSourceConfigurationManager.create(dataset.Title);
var url = "http://nicolas.kruchten.com/Rdatasets/csv/" + dataset.Package + "/" + dataset.Item + ".csv";
DataSourceConfigurationManager.dataSourceConfigurations[dataSourceConfigurationId].httpConfig = angular.toJson({method: 'GET', url: url });
});
}, function errorCallback(csvlist) {
// Do Nothing.
});
}
},
deleteRenderingEngine: function(id){
RenderingEngineManager.delete(id);
if(Object.keys(RenderingEngineManager.renderingEngines).length === 0){
$timeout(function() {
ServiceProvider.ExploreController.new();
}, 0);
}
},
initiateDataExploration: function(createNew){
if(controller.mainContentView !== "Explore"){
controller.mainContentView = "Explore";
}
if(createNew){
//Have to get on the call stack after the exploration-directive link function is executed
$timeout(function() {
ServiceProvider.ExploreController.new();
}, 0);
}
},
initiateDataSourceConfigurationWizard: function(){
if(controller.mainContentView !== "Data Source Configuration Wizard"){
controller.mainContentView = "Data Source Configuration Wizard";
}
},
initiateDashboard: function(){
if(controller.mainContentView !== "Dashboard Designer"){
controller.mainContentView = "Dashboard Designer";
}
},
sandboxMenusEnabled: function() {
return Object.keys(RenderingEngineManager.renderingEngines).length === 0;
}
};
$scope.Renderers = Renderers;
$scope.RenderingEngineManager = RenderingEngineManager;
$scope.UiControls = UiControls;
var controller = new Controller();
controller.init();
$scope.Controller = controller;
$scope.ServiceProvider = ServiceProvider;
}]);
angular.bootstrap($('body'), ['sampleApp']);
$('body').show();
});