loop-modules
Version:
Shared modules for the Loop product suite.
121 lines (120 loc) • 5.16 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 { Http } from '@angular/http';
// libs
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
// app
import { QueryAction, SetEntriesAction, SetSelectedAction } from '../actions/loop-topic.action';
import { APIDispatcher } from '../utils/index';
var LoopTopicService = (function (_super) {
__extends(LoopTopicService, _super);
function LoopTopicService(http, store) {
var _this = _super.call(this, http, store) || this;
_this.http = http;
_this.store = store;
return _this;
}
LoopTopicService.prototype.query = function (page, size, options) {
var _this = this;
if (page === void 0) { page = 0; }
if (size === void 0) { size = 10; }
if (options === void 0) { options = {}; }
return Observable.create(function (observer) {
if (_this.lastRequest) {
if (_this.lastRequest.options !== options) {
_this.lastRequest.currentPage = page;
_this.lastRequest.requestSize = size;
_this.lastRequest.options = options;
}
}
_this.get('ma_loop/api/v3/objections/fetch', page, size, options).map(function (res) { return res.json(); })
.catch(_this.handleError)
.subscribe(function (response) {
_this.loaded = true;
_this.lastRequest = response;
_this.lastRequest.currentPage = page;
_this.lastRequest.requestSize = size;
_this.lastRequest.options = options;
_this.store.dispatch(new QueryAction(response.content));
observer.next(response);
observer.complete();
});
});
};
LoopTopicService.prototype.fetch = function (identities) {
return this.post('ma_loop/api/v3/objections/fetch', identities)
.map(function (res) { return res.json(); })
.catch(this.handleError);
};
LoopTopicService.prototype.fetchForStore = function (identities) {
var _this = this;
return this.fetch(identities).subscribe(function (response) {
_this.loaded = true;
_this.store.dispatch(new QueryAction(response.content));
});
};
LoopTopicService.prototype.notes = function (identities) {
return this.http.post('ma_loop/api/v3/objections/notes', identities);
};
LoopTopicService.prototype.responses = function (identities) {
return this.http.post('ma_loop/api/v3/objections/rebuttals', identities);
};
LoopTopicService.prototype.updateNote = function (identity, note) {
return this.http.post('ma_loop/api/v3/objections/' + identity + '/note', note);
};
/**
* Fetches the next available page for topics, if any
*/
LoopTopicService.prototype.getNextPage = function () {
var _this = this;
if (this.hasNext && !this.fetchingNext) {
this.fetchingNext = true;
this.query(this.lastRequest.currentPage + 1, this.lastRequest.requestSize, this.lastRequest.options).subscribe(function () {
_this.fetchingNext = false;
});
}
};
/**
* Resets the entries in the app-state slice for Loop Topics
*
*
* @memberOf LoopTopicService
*/
LoopTopicService.prototype.resetEntries = function () {
this.loaded = false;
this.lastRequest = undefined;
this.store.dispatch(new SetEntriesAction([]));
};
/**
* Resets the selected entries in the app-state slice for Loop Topics
*
*
* @memberOf LoopTopicService
*/
LoopTopicService.prototype.resetSelectedEntries = function () {
this.store.dispatch(new SetSelectedAction([]));
};
return LoopTopicService;
}(APIDispatcher));
LoopTopicService = __decorate([
Injectable(),
__metadata("design:paramtypes", [Http, Store])
], LoopTopicService);
export { LoopTopicService };