Moved back to ng1
Change-Id: I43b284e3b3cb3ac19d43c088de988c89a7ea8807
diff --git a/src/app/rest/auth.rest.ts b/src/app/rest/auth.rest.ts
new file mode 100644
index 0000000..c72b51e
--- /dev/null
+++ b/src/app/rest/auth.rest.ts
@@ -0,0 +1,41 @@
+import {AppConfig} from '../config/app.config';
+import IHttpPromiseCallbackArg = angular.IHttpPromiseCallbackArg;
+export interface IAuthRequestData {
+ username: string;
+ password: string;
+}
+
+export interface IAuthResponseData extends IHttpPromiseCallbackArg<any> {
+ data: {
+ user: string;
+ xoscsrftoken: string;
+ xossessionid: string;
+ };
+}
+export class AuthService {
+
+
+ /** @ngInject */
+ constructor(
+ private $http: angular.IHttpService,
+ private $q: angular.IQService,
+ private $cookies: angular.cookies.ICookiesService
+ ) {
+ }
+
+ public login(data: IAuthRequestData): Promise<any> {
+ const d = this.$q.defer();
+ this.$http.post(`${AppConfig.apiEndpoint}/utility/login/`, data)
+ .then((res: IAuthResponseData) => {
+ this.$cookies.put('xoscsrftoken', res.data.xoscsrftoken);
+ this.$cookies.put('xossessionid', res.data.xossessionid);
+ this.$cookies.put('xosuser', res.data.user);
+ res.data.user = JSON.parse(res.data.user);
+ d.resolve(res.data);
+ })
+ .catch(e => {
+ d.reject(e);
+ });
+ return d.promise;
+ }
+}
diff --git a/src/app/rest/core.rest.ts b/src/app/rest/core.rest.ts
new file mode 100644
index 0000000..aace3aa
--- /dev/null
+++ b/src/app/rest/core.rest.ts
@@ -0,0 +1,18 @@
+import {AppConfig} from '../config/app.config';
+export class CoreRest {
+
+ /** @ngInject */
+ constructor(
+ private $http: angular.IHttpService,
+ private $q: angular.IQService
+ ) {
+ }
+
+ public query(): Promise<any> {
+ const d = this.$q.defer();
+ this.$http.get(`${AppConfig.apiEndpoint}/core/`)
+ .then(res => d.resolve(res.data))
+ .catch(d.reject);
+ return d.promise;
+ }
+}
diff --git a/src/app/rest/index.ts b/src/app/rest/index.ts
new file mode 100644
index 0000000..d28084b
--- /dev/null
+++ b/src/app/rest/index.ts
@@ -0,0 +1,11 @@
+import {CoreRest} from './core.rest';
+import {SlicesRest} from './slices.rest';
+import {AuthService} from './auth.rest';
+
+export const xosRest = 'xosRest';
+
+angular
+ .module('xosRest', ['ngCookies'])
+ .service('CoreRest', CoreRest)
+ .service('SlicesRest', SlicesRest)
+ .service('AuthService', AuthService);
diff --git a/src/app/rest/slices.rest.ts b/src/app/rest/slices.rest.ts
new file mode 100644
index 0000000..0d1d8a1
--- /dev/null
+++ b/src/app/rest/slices.rest.ts
@@ -0,0 +1,20 @@
+import {AppConfig} from '../config/app.config';
+
+export interface IXosResourceService {
+ getResource(): ng.resource.IResourceClass<any>;
+}
+
+export class SlicesRest implements IXosResourceService{
+ static $inject = ['$resource'];
+
+ /** @ngInject */
+ constructor(
+ private $resource: ng.resource.IResourceService
+ ) {
+
+ }
+
+ public getResource(): ng.resource.IResourceClass<ng.resource.IResource<any>> {
+ return this.$resource(`${AppConfig.apiEndpoint}/core/slices/`);
+ }
+}