loop-modules
Version:
Shared modules for the Loop product suite.
132 lines (131 loc) • 5.28 kB
JavaScript
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
// angular
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Http } from '@angular/http';
// libs
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
// libs
import { Store, } from '@ngrx/store';
// app
import { APIDispatcher } from '../utils/index';
import { QueryAction, SetEntriesAction } from '../actions/loop-activity.action';
var LoopActivityService = (function (_super) {
__extends(LoopActivityService, _super);
function LoopActivityService(http, store, router) {
var _this = _super.call(this, http, store) || this;
_this.http = http;
_this.store = store;
_this.router = router;
return _this;
}
LoopActivityService.prototype.query = function (page, size, filters) {
if (page === void 0) { page = 0; }
if (size === void 0) { size = 10; }
if (filters === void 0) { filters = ['scenario', 'objection', 'content']; }
return this.post('ma_loop/api/v1/activity/fetch', filters, page, size)
.map(function (res) { return res.json(); })
.catch(this.handleError);
};
LoopActivityService.prototype.queryForStore = function (page, size, filters) {
var _this = this;
if (page === void 0) { page = 0; }
if (size === void 0) { size = 10; }
if (filters === void 0) { filters = ['scenario', 'objection', 'content']; }
return this.query(page, size, filters).subscribe(function (response) {
_this.loaded = true;
_this.store.dispatch(new QueryAction(response.content));
});
};
LoopActivityService.prototype.save = function (payload) {
if (!payload) {
return;
}
this.http.post('ma_loop/api/v1/activity', [payload])
.catch(this.handleError)
.subscribe();
};
/**
* Gets the correct content title to display based on the tracked activity
*
* @param {LoopActivity} activity The activity to display
* @returns The title for the activity
*
* @memberOf RecentActivityComponent
*/
LoopActivityService.prototype.getTitle = function (activity) {
if (activity.scenario_title !== null) {
return activity.scenario_title;
}
if (activity.objection_title !== null) {
return activity.objection_title;
}
if (activity.content_title !== null) {
return activity.content_title;
}
// V2 tracking (possibly)
// if(activity.assignment_title !== null) {
// return activity.assignment_title;
// }
// if(activity.session_title !== null) {
// return activity.session_title;
// }
return '';
};
/**
* Handles the desired clickable action for viewing an activity
*
* @param {LoopActivity} activity The activity to view
*
* @memberOf RecentActivityComponent
*/
LoopActivityService.prototype.handleAction = function (activity) {
if (activity.scenario_identity !== null) {
this.router.navigate(['/main/content/scenarios/', activity.scenario_identity]);
}
if (activity.objection_identity !== null) {
this.router.navigate(['/main/content/topics/', activity.objection_identity]);
}
if (activity.content_identity !== null) {
this.router.navigate(['/main/content/documents/', activity.content_identity]);
}
// V2
// if(activity.assignment_identity !== null) {
// // TODO - View assignment
// }
// if(activity.session_identity !== null) {
// // TODO - View session
// }
};
/**
* Resets the entries in the app-state slice for LoopActivity
*
*
* @memberOf LoopActivityService
*/
LoopActivityService.prototype.resetEntries = function () {
this.loaded = false;
this.lastRequest = undefined;
this.store.dispatch(new SetEntriesAction([]));
};
return LoopActivityService;
}(APIDispatcher));
LoopActivityService = __decorate([
Injectable(),
__metadata("design:paramtypes", [Http, Store, Router])
], LoopActivityService);
export { LoopActivityService };