Commit f566d74a by Tuukka Kivilahti

moya-angular-common now contains common stuffendalen

1 parent 0a7abd21
Showing with 545 additions and 12 deletions
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
# dependencies
node_modules/
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# misc
/.sass-cache
/connect.lock
/coverage/*
/libpeerconnection.log
npm-debug.log
testem.log
/typings
# e2e
/e2e/*.js
/e2e/*.map
#System Files
.DS_Store
Thumbs.db
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>moya-angular-common</artifactId>
<groupId>fi.codecrew.moya.angular</groupId>
<version>0.001</version>
</project>
import { MoyaRestModule} from './moya-rest/moya-rest.module';
import {NgModule} from "@angular/core";
export * from './moya-rest';
const MODULES = [
MoyaRestModule
]
@NgModule({
imports: [MoyaRestModule.forRoot()],
exports: MODULES
})
@NgModule({exports: MODULES})
export class MoyaAngularCommonModule {
}
\ No newline at end of file
export * from "./moya-rest.module"
/**
* Created by tuukka on 15/02/17.
*/
"use strict";
// vim magic: %s/^\s*\w\+\s\+\(\w\+\)\s\+\(\w\+\)\s*.*;$/ \2: \L\1;/
(function (UserGender) {
UserGender[UserGender["MALE"] = 0] = "MALE";
UserGender[UserGender["FEMALE"] = 1] = "FEMALE";
UserGender[UserGender["UNSPECIFIED"] = 2] = "UNSPECIFIED";
})(exports.UserGender || (exports.UserGender = {}));
var UserGender = exports.UserGender;
var User = (function () {
function User() {
}
return User;
}());
exports.User = User;
/**
* Created by tuukka on 04/02/17.
*/
"use strict";
var VipProductDelivery = (function () {
function VipProductDelivery() {
}
return VipProductDelivery;
}());
exports.VipProductDelivery = VipProductDelivery;
"use strict";
/**
* Created by tuukka on 04/02/17.
*/
var VipProduct = (function () {
function VipProduct() {
}
return VipProduct;
}());
exports.VipProduct = VipProduct;
"use strict";
/**
* Created by tuukka on 04/02/17.
*/
var Vip = (function () {
function Vip() {
}
return Vip;
}());
exports.Vip = Vip;
"use strict";
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 core_1 = require('@angular/core');
var common_1 = require('@angular/common');
var http_1 = require("@angular/http");
var moya_rest_service_1 = require("./services/moya-rest.service");
var viplist_service_1 = require("./services/viplist.service");
var cache_service_1 = require("./services/cache.service");
var user_service_1 = require("./services/user.service");
var MoyaRestModule = (function () {
function MoyaRestModule() {
}
MoyaRestModule.forRoot = function () {
return {
ngModule: MoyaRestModule,
providers: [
moya_rest_service_1.MoyaRestService,
viplist_service_1.ViplistService,
cache_service_1.CacheService,
user_service_1.UserService
]
};
};
MoyaRestModule = __decorate([
core_1.NgModule({
imports: [
common_1.CommonModule,
http_1.HttpModule
],
declarations: []
})
], MoyaRestModule);
return MoyaRestModule;
}());
exports.MoyaRestModule = MoyaRestModule;
......@@ -6,6 +6,16 @@ import {ViplistService} from "./services/viplist.service";
import {CacheService} from "./services/cache.service";
import {UserService} from "./services/user.service";
export * from "./services/moya-rest.service";
export * from "./services/viplist.service";
export * from "./services/cache.service";
export * from "./services/user.service";
export * from "./models/user.model";
export * from "./models/vip.model";
export * from "./models/vip-product.model";
export * from "./models/vip-product-delivery.model";
@NgModule({
imports: [
......@@ -14,6 +24,7 @@ import {UserService} from "./services/user.service";
],
declarations: []
})
export class MoyaRestModule {
......
"use strict";
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 core_1 = require("@angular/core");
var rxjs_1 = require("rxjs");
var DEFAULT_EXPIRE_MS = 300000; // 5min
var CachedItem = (function () {
function CachedItem(moduleName, path, value, isObservable) {
this.moduleName = moduleName;
this.path = path;
this.value = value;
this.expires = new Date();
this.expires.setTime(Date.now() + DEFAULT_EXPIRE_MS);
this.isObservable = isObservable;
}
CachedItem.prototype.isExpired = function () {
return this.expires.getTime() < Date.now();
};
return CachedItem;
}());
/**
* Basic cacheService.
*
* First this was part of moyaRestService, but I thinked that if cache is too easy to use, someone will kill this application with it.
* So let's make it litlebit harder
*/
var CacheService = (function () {
// TODO: timed clearup for cache to save memory
function CacheService(zone) {
this.zone = zone;
this.cache = new Map();
this.timerObservable = rxjs_1.Observable.timer(30000, 30000); // afther 0.5min, every 0.5min.
}
/**
* This will return observable with value from cache, or cache value from your observable and return it in observable.
*
* example: return cacheService.cacheObservable("mymodule",<url>, http.get(<url>).map(v => v.json()));
*
* @param moduleName
* @param cachePath
* @param source: {Observable<any>} Observable where the values, which are cached, is coming from
* @return {Observable<any>}: if value is in cache, this is observable made from this value. Otherwise this is source observable.
*/
CacheService.prototype.cacheObservable = function (moduleName, cachePath, source) {
var _this = this;
var cacheName = this.generateCachename(moduleName, cachePath);
if (this.cache.has(cacheName) && this.cache.get(cacheName).expires.getTime() < Date.now()) {
console.log(cacheName, " Expired version in cache");
this.cache.delete(cacheName);
}
if (!this.cache.has(cacheName)) {
/*
not in cache, let's change source to hot -observable, and return one instance from it
problem is, that before this observable is runned, there can be queries for this value from cache.
So, let's change this to hot-observable, and put that hot-observable into the cache.
And in first run, we change this hot observable to it's value.
Javascript is asynchronous, so there is no need to worry some weird things that could happen in multithreaded languages.
*/
console.log(cacheName, " not in cache");
var hotSource = source
.do(function (val) { return _this.cache.set(cacheName, new CachedItem(moduleName, cachePath, val)); })
.publishLast().refCount();
this.cache.set(cacheName, new CachedItem(moduleName, cachePath, hotSource, true));
this.checkCleanTimer();
return hotSource;
}
var cacheItem = this.cache.get(cacheName);
// if value is hotObservable, return it, otherwise create observable from value
if (cacheItem.isObservable) {
console.log(cacheName, " hot observable in cache ");
return cacheItem.value;
}
console.log(cacheName, " value in cache");
this.checkCleanTimer();
return rxjs_1.Observable.of(cacheItem.value);
};
CacheService.prototype.clean = function () {
this.cache.clear();
this.checkCleanTimer();
};
CacheService.prototype.cleanExpired = function () {
var _this = this;
this.cache.forEach(function (v, k) {
if (v.isExpired()) {
console.log(k, " Cache expired");
_this.cache.delete(k);
}
});
this.checkCleanTimer();
};
CacheService.prototype.checkCleanTimer = function () {
var _this = this;
if (this.cache.size > 0) {
if (!this.timerSubscription) {
console.log("adding clearing timer");
this.zone.runOutsideAngular(function () {
_this.timerSubscription = _this.timerObservable.subscribe(function (v) {
_this.cleanExpired();
});
});
}
}
else {
if (this.timerSubscription) {
console.log("removing clearing timer");
this.timerSubscription.unsubscribe();
}
}
};
/**
*
* @param moduleName
* @param cachePath
* @param value
*/
CacheService.prototype.set = function (moduleName, cachePath, value) {
var cacheName = this.generateCachename(moduleName, cachePath);
this.cache.set(cacheName, new CachedItem(moduleName, cachePath, value));
};
/**
* Get one value from cache.
*
* Now when there is this observablethingy. Make public afther rethinking this.
*
* @param moduleName
* @param cachePath
* @return {any|null} Null if nothing is in cache.
*/
CacheService.prototype.get = function (moduleName, cachePath) {
var cacheName = this.generateCachename(moduleName, cachePath);
if (this.cache.has(cacheName) && this.cache.get(cacheName).expires.getTime() < Date.now()) {
this.cache.delete(cacheName);
}
if (this.cache.has(cacheName)) {
return this.cache.get(cacheName);
}
return null;
};
CacheService.prototype.generateCachename = function (moduleName, cachePath) {
return moduleName + "::" + cachePath;
};
CacheService = __decorate([
core_1.Injectable()
], CacheService);
return CacheService;
}());
exports.CacheService = CacheService;
"use strict";
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 core_1 = require('@angular/core');
var rxjs_1 = require("rxjs");
var MoyaRestService = (function () {
function MoyaRestService(http) {
this.http = http;
}
MoyaRestService.prototype.post = function (subUrl, body, pathParameters) {
return this.http.post(this.genUrl(subUrl, pathParameters), body)
.map(this.handleResponse)
.catch(this.handleException);
};
MoyaRestService.prototype.put = function (subUrl, body, pathParameters) {
return this.http.put(this.genUrl(subUrl, pathParameters), body)
.map(this.handleResponse)
.catch(this.handleException);
};
MoyaRestService.prototype.delete = function (subUrl, pathParameters) {
return this.http.delete(this.genUrl(subUrl, pathParameters))
.map(this.handleResponse)
.catch(this.handleException);
};
MoyaRestService.prototype.get = function (subUrl, pathParameters) {
return this.http.get(this.genUrl(subUrl, pathParameters))
.map(this.handleResponse)
.catch(this.handleException);
};
MoyaRestService.prototype.genUrl = function (subUrl, urlParams) {
var suffix = "";
if (urlParams) {
urlParams.forEach(function (value, key) {
if (suffix.length <= 0) {
suffix = "?";
}
else {
suffix += "&";
}
suffix += key + "=" + value;
});
}
return "/MoyaWeb/rest/" + subUrl + suffix; // <-- TODO: kauneista
};
MoyaRestService.prototype.handleResponse = function (res) {
// basicly, 200 statuscodes means success
if (!(res.status >= 200 && res.status <= 299)) {
console.log("statuscode not between 200 and 299", res.status);
// next stop: handlerException
throw res;
}
return res;
};
MoyaRestService.prototype.handleException = function (error) {
console.log("error on jira rest connection", error);
// TODO: add handlers to 403's and other "not logged in" or "invalid permissions" -statuscodes, and route them using some nice global parameter
return rxjs_1.Observable.throw(error);
};
MoyaRestService = __decorate([
core_1.Injectable()
], MoyaRestService);
return MoyaRestService;
}());
exports.MoyaRestService = MoyaRestService;
"use strict";
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 core_1 = require("@angular/core");
var rxjs_1 = require("rxjs");
var UserService = (function () {
function UserService(moyaRest, cacheService) {
this.moyaRest = moyaRest;
this.cacheService = cacheService;
}
UserService.prototype.get = function (id) {
if (!id || id < 0) {
return rxjs_1.Observable.throw("There should be userid");
}
var path = "v2/user/" + id;
return this.cacheService.cacheObservable("moya:UserService", path, this.moyaRest.get(path)
.do(function (v) { console.log("getting user outside of cache", path); })
.map(function (res) { return (res.json()); }));
};
UserService = __decorate([
core_1.Injectable()
], UserService);
return UserService;
}());
exports.UserService = UserService;
"use strict";
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
});
};
var core_1 = require('@angular/core');
var rxjs_1 = require("rxjs");
var ViplistService = (function () {
function ViplistService(moyaRestService, userService) {
this.moyaRestService = moyaRestService;
this.userService = userService;
}
/**
* get vips
* @param searchString: searchString, skip to return all vips
*/
ViplistService.prototype.get = function (searchString) {
var _this = this;
if (!searchString) {
return this.moyaRestService.get("v3/vip/all")
.switchMap(function (res) { return rxjs_1.Observable.forkJoin.apply(rxjs_1.Observable, res.json().map(function (apiRow) { return _this.hostPopulator(apiRow); })); });
}
return this.moyaRestService.get("v3/vip/search/" + searchString)
.switchMap(function (v) { return rxjs_1.Observable.forkJoin.apply(rxjs_1.Observable, v.json().map(function (x) { return _this.hostPopulator(x); })); });
};
/**
* Delete vip.
*
* @param vip
* @return Observable
*/
ViplistService.prototype.delete = function (vip) {
return __awaiter(this, void 0, Promise, function* () {
if (!vip.id)
throw new Error("TODO: errori, tyhmä vippi");
var res = yield this.moyaRestService.delete("v3/vip/" + vip.id)
.first()
.toPromise();
return res.ok;
});
};
/*
public deleteProm(vip: Vip): Promise<boolean> {
if (!vip.id)
throw new Error("TODO: errori, tyhmä vippi");
return this.moyaRestService.delete("v3/vip/" + vip.id)
.first()
.toPromise()
.then(r => r.ok);
}
*/
ViplistService.prototype.getWithId = function (id) {
return this.moyaRestService.get("v3/vip/" + id)
.map(function (v) { return v.json(); });
};
ViplistService.prototype.create = function (vip) {
return this.moyaRestService.post("v3/vip/create", vip)
.map(function (v) { return v.json(); });
};
ViplistService.prototype.hostPopulator = function (rawVip) {
return this.userService.get(rawVip.hostId)
.map(function (u) { rawVip.host = u; return rawVip; });
};
ViplistService = __decorate([
core_1.Injectable()
], ViplistService);
return ViplistService;
}());
exports.ViplistService = ViplistService;
{
"name": "moya-angular-common",
"version": "0.0.1",
"license": "UNLICENSED",
"scripts": {},
"private": true,
"peerDependencies": {
"@angular/common": "^4.1.2",
"@angular/compiler": "^4.1.2",
"@angular/core": "^4.1.2",
"@angular/forms": "^4.1.2",
"@angular/http": "^4.1.2",
"@angular/material": "^2.0.0-beta.1",
"@angular/platform-browser": "^4.1.2",
"@angular/platform-browser-dynamic": "^4.1.2",
"@angular/router": "^4.1.2"
}
}
{
"compilerOptions": {
"baseUrl": "",
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es6", "dom"],
"mapRoot": "./",
"module": "es6",
"moduleResolution": "node",
"outDir": "../dist/out-tsc",
"sourceMap": true,
"target": "es5",
"typeRoots": [
"../node_modules/@types"
]
}
}
{
"name": "moya-angular",
"version": "0.0.0",
"license": "MIT",
"license": "UNLICENSED",
"angular-cli": {},
"scripts": {},
"private": true,
"dependencies": {
"@angular/animations": "^4.1.2",
"@angular/cli": "^1.0.3",
"@angular/common": "^4.1.2",
"@angular/compiler": "^4.1.2",
"@angular/core": "^4.1.2",
......@@ -17,6 +19,7 @@
"@angular/router": "^4.1.2",
"bootstrap": "^4.0.0-alpha.6",
"core-js": "^2.4.1",
"moya-angular-common": "file:///Users/tuukka/Projects/moya/code/moya-angular-common/src",
"ng2-bootstrap": "^1.3.3",
"node-sass": "^4.5.0",
"rxjs": "^5.0.1",
......@@ -29,7 +32,6 @@
"@angularclass/hmr": "^1.2.2",
"@types/jasmine": "2.5.47",
"@types/node": "^7.0.18",
"angular-cli": "1.0.0-beta.28.3",
"codelyzer": "~3.0.1",
"jasmine-core": "2.6.1",
"jasmine-spec-reporter": "4.1.0",
......
......@@ -6,11 +6,10 @@ import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { ViplistComponent } from './viplist/viplist.component';
import {AlertModule} from "ng2-bootstrap";
import {MoyaRestModule} from "./moya-rest/moya-rest.module";
import {MoyaRestModule} from "moya-angular-common";
import { RouterModule, Routes } from '@angular/router';
import {TestComponent} from "./test/test.component";
import {MaterialModule} from "@angular/material";
const appRoutes: Routes = [
{ path: 'vip/viplist', component: ViplistComponent },
......@@ -22,13 +21,12 @@ const appRoutes: Routes = [
declarations: [
AppComponent,
ViplistComponent,
TestComponent
TestComponent,
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
MaterialModule.forRoot(),
AlertModule.forRoot(),
MoyaRestModule.forRoot() ,
RouterModule.forRoot(appRoutes)
......
import { Component, OnInit } from '@angular/core';
import {ViplistService} from "../moya-rest/services/viplist.service";
import {Observable} from "rxjs";
import {Vip} from "../moya-rest/models/vip.model";
import {AsyncPipe} from "@angular/common";
import {ViplistService, Vip} from "moya-angular-common";
@Component({
selector: 'moya-viplist',
......
/* You can add global styles to this file, and also import other style files */
@import '~@angular/material/core/theming/prebuilt/indigo-pink.css';
@import '~@angular/material/prebuilt-themes/indigo-pink.css';
......@@ -264,7 +264,7 @@ public class MenuBean implements MenuBeanLocal {
vips.addPage(menuitemfacade.findOrCreate("/vip/multiadd"), VipPermission.EDIT);
vips.addPage(menuitemfacade.findOrCreate("/vip/deliver"), VipPermission.VIEW).setVisible(false);
vips.addPage(menuitemfacade.findOrCreate("/vip/edit"), VipPermission.VIEW).setVisible(false);
adminuser.addPage(menuitemfacade.findOrCreate("/angular/vip/viplist", true), null);
//adminuser.addPage(menuitemfacade.findOrCreate("/angular/vip/viplist", true), null);
MenuNavigation adminAssociation = adminmenu.addPage(null, null);
adminAssociation.setKey("topnavi.adminassoc");
......
......@@ -18,6 +18,7 @@
<module>../moya-terminal-web</module>
<module>../moya-ear</module>
<module>../moya-angular</module>
<module>../moya-angular-common</module>
</modules>
<dependencies>
......
......@@ -15,7 +15,6 @@ import java.util.List;
* V3 version of vipstuff, eventuser -> user
*/
@XmlRootElement()
@ApiModel(description = "vip")
public class VipRestPojoV3 {
public Integer id;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!