Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit f70c020

Browse files
author
Callan Milne
authored
Merge pull request #4 from data-studio/feature/app-editor-enhancements
Feature/app editor enhancements
2 parents dece784 + 9f0e12a commit f70c020

21 files changed

Lines changed: 880 additions & 325 deletions

src/app/modules/api/dsApi.es

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
dsApiFactory.$inject = ['$auth', '$appEnvironment', '$http'];
66
function dsApiFactory ( $auth, $appEnvironment, $http) {
77

8-
const POST = "post";
9-
const GET = "get";
8+
const POST = 'post';
9+
const GET = 'get';
10+
const DELETE = 'delete';
1011

1112
class DsApi {
1213
constructor () {
@@ -51,6 +52,25 @@
5152
opts.data = JSON.stringify(d);
5253
}
5354

55+
$http(opts).then(resolve, reject);
56+
});
57+
}
58+
apiDelete (url) {
59+
let dsApi = this;
60+
return new Promise((resolve, reject) => {
61+
let authorization = this.authorization;
62+
let opts = {
63+
method: DELETE,
64+
url: dsApi.url + url,
65+
headers: {
66+
'Content-Type': 'application/json; charset=utf-8',
67+
},
68+
};
69+
70+
if (hasAuthorization()) {
71+
opts.headers['Authorization'] = getAuthorization();
72+
}
73+
5474
$http(opts).then(resolve, reject);
5575
});
5676
}

src/app/modules/app/app.scss

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,20 @@ md-content.ds-main-content {
108108
}
109109
}
110110

111-
.user-dashboard md-card {
112-
cursor: pointer;
113-
}
111+
.user-dashboard {
112+
md-card {
113+
cursor: pointer;
114+
}
114115

116+
header {
117+
padding: 24px;
118+
background-color: #212121;
119+
color: rgba(255,255,255,1);
120+
}
121+
header .md-subhead {
122+
color: rgba(0,0,0,0.38);
123+
}
124+
}
115125
.user-dashboard .create-app-card {
116126
height: 125px;
117127
margin: 8px;
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
2+
angular.module('DataStudioWebui.AppEditor')
3+
.factory('ApiSchema', ApiSchemaFactory);
4+
5+
ApiSchemaFactory.$inject = [];
6+
function ApiSchemaFactory () {
7+
8+
class ApiSchema {
9+
constructor (operations, routes) {
10+
this.operations = operations;
11+
this.routes = routes;
12+
}
13+
toJSON () {
14+
let operations = this.operations;
15+
let routes = this.routes;
16+
let paths = {};
17+
let routePaths = {};
18+
19+
routes.forEach(route => {
20+
let path = route.Path;
21+
paths[path] = {};
22+
routePaths[route.Id] = path;
23+
});
24+
25+
operations.forEach(operation => {
26+
27+
let op;
28+
let method;
29+
30+
let targetPath = routePaths[operation.RouteId];
31+
32+
let pathExists = targetPath in paths;
33+
if (!pathExists) {
34+
return;
35+
}
36+
37+
method = operation.Method;
38+
op = {
39+
operationId: operation.Name,
40+
summary: '',
41+
description: '',
42+
tags: [],
43+
consumes: [
44+
'application/json',
45+
],
46+
produces: [
47+
'application/json',
48+
],
49+
params: [],
50+
responses: {},
51+
};
52+
53+
decorate(op, method, targetPath);
54+
55+
paths[targetPath][method] = op;
56+
57+
});
58+
59+
return {
60+
swagger: '2.0',
61+
info: {
62+
title: '',
63+
description: '',
64+
version: '0.0.0-ALPHA',
65+
contact: {
66+
email: '',
67+
},
68+
license: {
69+
name: '',
70+
url: '',
71+
},
72+
},
73+
host: 'api.localhost',
74+
basePath: '/',
75+
tags: [],
76+
schemes: [
77+
'http',
78+
'https',
79+
],
80+
paths: paths,
81+
definitions: {},
82+
};
83+
84+
}
85+
};
86+
87+
return ApiSchema;
88+
89+
function decorate (op, method, uri) {
90+
91+
let uriParts = uri.split(/\//g).slice(1);
92+
let className = '';
93+
94+
uriParts.forEach(uriPart => {
95+
let isVariable = ':' === uriPart[0];
96+
if (!isVariable) {
97+
let c = uriPart[0].toUpperCase();
98+
className = c + uriPart.substr(1);
99+
className = className.replace(/ies$/, 'y');
100+
className = className.replace(/s$/, '');
101+
op.tags.push(className);
102+
return;
103+
}
104+
op.params.push({
105+
in: 'path',
106+
name: uriPart.substr(1),
107+
description: '',
108+
required: true,
109+
type: 'string',
110+
});
111+
});
112+
113+
if ('post' === method) {
114+
add303Response(op);
115+
add400Response(op);
116+
add401Response(op);
117+
add403Response(op);
118+
op.params.push({
119+
in: 'body',
120+
name: 'body',
121+
description: `The new \`${className}\``,
122+
required: true,
123+
schema: {
124+
$ref: `#/definitions/New${className}`,
125+
},
126+
});
127+
}
128+
129+
if ('get' === method) {
130+
add200Response(op);
131+
add404Response(op);
132+
}
133+
134+
if ('put' === method) {
135+
add200Response(op);
136+
add202Response(op);
137+
add400Response(op);
138+
add401Response(op);
139+
add403Response(op);
140+
op.params.push({
141+
in: 'body',
142+
name: 'body',
143+
description: `The \`${className}\` data to save`,
144+
required: true,
145+
schema: {
146+
$ref: `#/definitions/${className}`,
147+
},
148+
});
149+
}
150+
151+
if ('delete' === method) {
152+
add204Response(op);
153+
add401Response(op);
154+
add403Response(op);
155+
add404Response(op);
156+
}
157+
158+
function add200Response (op) {
159+
op.responses['200'] = {
160+
description: 'OK',
161+
schema: {
162+
$ref: `#/definitions/${className}`,
163+
},
164+
};
165+
}
166+
167+
function add202Response (op) {
168+
op.responses['202'] = {
169+
description: 'Accepted',
170+
};
171+
}
172+
173+
function add204Response (op) {
174+
op.responses['204'] = {
175+
description: 'No Content',
176+
};
177+
}
178+
179+
function add303Response (op) {
180+
op.responses['303'] = {
181+
description: 'See Other',
182+
};
183+
}
184+
185+
function add400Response (op) {
186+
op.responses['400'] = {
187+
description: 'Bad Request',
188+
};
189+
}
190+
191+
function add401Response (op) {
192+
op.responses['401'] = {
193+
description: 'Unauthorized',
194+
};
195+
}
196+
197+
function add403Response (op) {
198+
op.responses['403'] = {
199+
description: 'Forbidden',
200+
};
201+
}
202+
203+
function add404Response (op) {
204+
op.responses['404'] = {
205+
description: 'Not Found',
206+
};
207+
}
208+
209+
}
210+
211+
}

src/app/modules/appEditor/appApiEditorController.es

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,47 @@
55
AppApiEditorController.$inject = ['$api', '$timeout', '$scope', '$state', '$mdDialog', 'api', 'routes', 'operations'];
66
function AppApiEditorController ( $api, $timeout, $scope, $state, $mdDialog, api, routes, operations) {
77

8+
let originatorEv;
9+
810
let $apiCtrl = this;
911

1012
$apiCtrl.api = api;
1113

1214
$apiCtrl.operations = operations;
1315
$apiCtrl.routes = routes;
1416

17+
$apiCtrl.openMenu = function ($mdMenu, $event) {
18+
originatorEv = $event;
19+
$mdMenu.open($event);
20+
};
21+
22+
$apiCtrl.switchApi = function (apiId) {
23+
if (!apiId) {
24+
return;
25+
}
26+
$state.go('app.user.app.api', { apiId: apiId });
27+
};
28+
29+
$apiCtrl.deleteOperation = function (operation) {
30+
let operationId = operation.Id;
31+
if (!operationId) {
32+
return;
33+
}
34+
$api.apiDelete('/operation/' + operationId)
35+
.then(function (res) {
36+
$timeout(function () {
37+
let routeId = operation.RouteId;
38+
let i = $apiCtrl.operations.all.indexOf(operation);
39+
let l = $apiCtrl.operations.byRouteId[routeId].indexOf(operation);
40+
$apiCtrl.operations.all.splice(i, 1);
41+
$apiCtrl.operations.byRouteId[routeId].splice(l, 1);
42+
});
43+
})
44+
.catch(function (err) {
45+
console.log(err);
46+
});
47+
};
48+
1549
$apiCtrl.showSchemaView = function ($event) {
1650

1751
let schemaView = {
@@ -96,9 +130,9 @@
96130

97131
var confirm = $mdDialog.prompt()
98132
.title('Specify the Route Path')
99-
.placeholder('/my/api/path')
133+
.placeholder('/object/:objectId')
100134
.ariaLabel('Route Path')
101-
.initialValue('/my/api/path')
135+
.initialValue('')
102136
.targetEvent($event)
103137
.ok('Create Route')
104138
.cancel('Cancel');
@@ -137,28 +171,3 @@
137171
}
138172

139173
}
140-
141-
angular.module('DataStudioWebui.AppEditor')
142-
.controller('CreateApiOperationDialogController', CreateApiOperationDialogController);
143-
144-
CreateApiOperationDialogController.$inject = ['$scope', '$mdDialog', 'apiRoute'];
145-
function CreateApiOperationDialogController ( $scope, $mdDialog, apiRoute) {
146-
$scope.$data = {
147-
Method: 'get',
148-
_apiRoute: apiRoute,
149-
};
150-
151-
$scope.apiRoute = apiRoute;
152-
153-
$scope.hide = function() {
154-
$mdDialog.cancel();
155-
};
156-
157-
$scope.cancel = function() {
158-
$mdDialog.cancel();
159-
};
160-
161-
$scope.answer = function() {
162-
$mdDialog.hide($scope.$data);
163-
};
164-
}

0 commit comments

Comments
 (0)