Skip to content

Commit b8ee73a

Browse files
author
Hamlet Hakobyan
committed
Added support for copy, count, metadata, namedQuery, remove, report, search. Made some refactoring. Improved unit test coverage. Added examples for usage.
1 parent 71affe4 commit b8ee73a

36 files changed

+675
-89
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/dist/**

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.vscode/
22
node_modules/
33
bower_components/
4+
dist/
5+
/o365.*

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@
22
A Workfront Stream API for AngularJS
33

44
Supported API version: 5.0, unsupported, internal
5+
6+
examples
7+
8+
run webpack-dev-server --host 127.0.0.1 --port 443 --content-base ./examples --devtool sourcemap --https --key o365.key --cert o365.crt
9+
set hosts 127.0.0.1 o365.attask-ondemand.com
10+
browse https://o365.attask-ondemand.com/index.html

examples/app.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* global angular */
2+
'use strict';
3+
4+
angular.module('testApp', ['streamApi'])
5+
.controller('testController', ['streamApiService', function(streamApiService) {
6+
this.doLogin = function() {
7+
var self = this;
8+
self.loginData = {};
9+
try {
10+
var streamApi = streamApiService.getInstance({url: self.host, version:'5.0'});
11+
} catch(e) {
12+
self.loginData = e.message;
13+
}
14+
15+
streamApi.login(self.username, self.password)
16+
.then(function(response) {
17+
self.loginData.loginData = response.data;
18+
var params = {};
19+
params['name'] = 'task ^&%$#@!~`';
20+
// params['status' + streamApi.Constants.MOD] = streamApi.Constants.Operators.NOTEQUAL;
21+
params[streamApi.Constants.LIMIT] = 1;
22+
return streamApi.search('task', params, 'ID');
23+
})
24+
.then(function(response) {
25+
self.loginData.searchedTask = response.data;
26+
var params = {};
27+
params['status'] = 'NEW';
28+
// params['status' + streamApi.Constants.MOD] = streamApi.Constants.Operators.NOTEQUAL;
29+
params[streamApi.Constants.LIMIT] = 1;
30+
return streamApi.search('project', params, 'ID');
31+
})
32+
.then(function(response) {
33+
self.loginData.projectData = response.data;
34+
var data = {
35+
name: 'Task created by angular-stream-api',
36+
projectID: response.data.data[0].ID
37+
};
38+
return streamApi.create('task', data);
39+
})
40+
.then(function(response) {
41+
self.loginData.createdTask = response.data;
42+
var actionArgs = {
43+
userIDs: [streamApi.Constants.WildCards.USER],
44+
roleIDs: []
45+
};
46+
return streamApi.execute('task', response.data.data.ID, 'assignMultiple', actionArgs);
47+
})
48+
.then(function(response) {
49+
self.loginData.assignedTask = response.data;
50+
return streamApi.execute('task', response.data.data.ID, 'markDone');
51+
})
52+
.then(function(response) {
53+
self.loginData.doneTask = response.data;
54+
})
55+
.catch(function(error) {
56+
self.loginData.error = error;
57+
});
58+
};
59+
}]);

examples/index.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head lang="en">
4+
<meta charset="UTF-8">
5+
<title>Login example</title>
6+
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"/>
7+
8+
<!-- The script below is not needed if your browser supports ES6 promises -->
9+
10+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
11+
<script src="../dist/angular-stream-api.js"></script>
12+
<script src="app.js"></script>
13+
</head>
14+
<body ng-app="testApp">
15+
<div class="container">
16+
<div ng-controller="testController as vm">
17+
<div class="form-group">
18+
<label for="url">Url</label>
19+
<input type="text" class="form-control" id="url" ng-model="vm.host" placeholder="Url to use for connection to Workfront">
20+
</div>
21+
22+
<div class="form-group">
23+
<label for="username">Username</label>
24+
<input type="text" class="form-control" id="username" ng-model="vm.username" placeholder="Your Workfront login">
25+
</div>
26+
<div class="form-group">
27+
<label for="password">Password</label>
28+
<input type="text" class="form-control" id="password" ng-model="vm.password" placeholder="Your Workfront password">
29+
</div>
30+
<div class="form-group">
31+
<label for="login-data">Login Data</label>
32+
<textarea id="login-data">{{vm.loginData | json}}</textarea>
33+
</div>
34+
35+
<button type="submit" class="btn btn-default" ng-click="vm.doLogin()">Login</button>
36+
</div>
37+
</div>
38+
</body>
39+
</html>

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"karma-webpack": "^1.7.0",
3636
"phantomjs-prebuilt": "^2.1.7",
3737
"url-parse": "^1.1.1",
38-
"webpack": "^1.13.1"
38+
"webpack": "^1.13.1",
39+
"webpack-dev-server": "^1.14.1"
3940
}
4041
}

src/ApiServiceProvider.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ function streamApiServiceProvider() {
77
this.$get = streamApiServiceFactory;
88
}
99

10-
streamApiServiceFactory.$inject = ['$http', '$q'];
11-
function streamApiServiceFactory($http, $q) {
10+
streamApiServiceFactory.$inject = ['$http', '$httpParamSerializer', '$q'];
11+
function streamApiServiceFactory($http, $httpParamSerializer, $q) {
1212
var Api = require('./service/Api'),
1313
factory = {},
1414
_instance;
1515

1616
Api.prototype.http = $http;
17+
Api.prototype.serializer = $httpParamSerializer;
1718
Api.prototype.promise = $q;
1819

1920
factory.getInstance = function(config, returnNewInstance) {

src/service/Api.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,10 @@ require('./edit')(Api);
4747
require('./login')(Api);
4848
require('./logout')(Api);
4949
require('./execute')(Api);
50+
require('./search')(Api);
51+
require('./metadata')(Api);
52+
require('./namedQuery')(Api);
53+
require('./report')(Api);
54+
require('./remove')(Api);
5055

5156
module.exports = Api;

src/service/copy.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
module.exports = function(Api) {
44
Api.prototype.copy = function (objCode, objID, updates, fields) {
5+
if(!objCode || !objID) {
6+
throw new Error('You must provide at least objCode and objID');
7+
}
58
var params = {
69
copySourceID: objID
710
};
8-
11+
912
return this.request(objCode, updates, params, fields, this.Methods.POST);
1013
};
1114
};

src/service/count.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
module.exports = function(Api) {
44
Api.prototype.count = function(objCode, query) {
5+
if(!objCode) {
6+
throw new Error('You must provide \'objCode\'');
7+
}
58
var path = objCode + '/count';
6-
return this.request(path, null, query, null, this.Methods.GET)
9+
return this.request(path, undefined, query, undefined, this.Methods.GET)
710
.then(function(response) {
811
if(response.data && response.data.count) {
912
return response.data.count;

0 commit comments

Comments
 (0)