diff --git a/api/src/main/java/com/maptology/api/Page.java b/api/src/main/java/com/maptology/api/Page.java index 52bb61f..04cd08c 100644 --- a/api/src/main/java/com/maptology/api/Page.java +++ b/api/src/main/java/com/maptology/api/Page.java @@ -11,6 +11,7 @@ import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -58,6 +59,7 @@ public abstract class Page { */ @XmlElementWrapper @XmlElement(name="element") + @JsonProperty(value="elements") // force jackson to keep the name private List elements = new ArrayList<>(); /** diff --git a/web/angular/package-lock.json b/web/angular/package-lock.json index 4a5f248..0427e49 100644 --- a/web/angular/package-lock.json +++ b/web/angular/package-lock.json @@ -37,6 +37,11 @@ "rxjs": "5.5.2" } }, + "@angular-redux/store": { + "version": "6.5.7", + "resolved": "https://developer.locoslab.com/sinopia/@angular-redux%2fstore/-/store-6.5.7.tgz", + "integrity": "sha1-IsO0gVyJ1sygrJPd23yr7Dlm8fw=" + }, "@angular/animations": { "version": "5.0.1", "resolved": "https://developer.locoslab.com/sinopia/@angular%2fanimations/-/animations-5.0.1.tgz", @@ -5014,8 +5019,7 @@ "js-tokens": { "version": "3.0.2", "resolved": "https://developer.locoslab.com/sinopia/js-tokens/-/js-tokens-3.0.2.tgz", - "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=", - "dev": true + "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=" }, "js-yaml": { "version": "3.7.0", @@ -5374,8 +5378,12 @@ "lodash": { "version": "4.17.4", "resolved": "https://developer.locoslab.com/sinopia/lodash/-/lodash-4.17.4.tgz", - "integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4=", - "dev": true + "integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4=" + }, + "lodash-es": { + "version": "4.17.4", + "resolved": "https://developer.locoslab.com/sinopia/lodash-es/-/lodash-es-4.17.4.tgz", + "integrity": "sha1-3MHXVS4VCgZABzupyzHXDwMpUOc=" }, "lodash._basecopy": { "version": "3.0.1", @@ -5616,7 +5624,6 @@ "version": "1.3.1", "resolved": "https://developer.locoslab.com/sinopia/loose-envify/-/loose-envify-1.3.1.tgz", "integrity": "sha1-0aitM/qc4OcT1l/dCsi3SNR4yEg=", - "dev": true, "requires": { "js-tokens": "3.0.2" } @@ -7899,6 +7906,17 @@ } } }, + "redux": { + "version": "3.7.2", + "resolved": "https://developer.locoslab.com/sinopia/redux/-/redux-3.7.2.tgz", + "integrity": "sha512-pNqnf9q1hI5HHZRBkj3bAngGZW/JMCmexDlOxw4XagXY2o1327nHH54LoTjiPJ0gizoqPDRqWyX/00g0hD6w+A==", + "requires": { + "lodash": "4.17.4", + "lodash-es": "4.17.4", + "loose-envify": "1.3.1", + "symbol-observable": "1.0.4" + } + }, "reflect-metadata": { "version": "0.1.10", "resolved": "https://developer.locoslab.com/sinopia/reflect-metadata/-/reflect-metadata-0.1.10.tgz", diff --git a/web/angular/package.json b/web/angular/package.json index 2acc7ac..e139484 100644 --- a/web/angular/package.json +++ b/web/angular/package.json @@ -14,6 +14,7 @@ }, "private": true, "dependencies": { + "@angular-redux/store": "^6.5.7", "@angular/animations": "^5.0.0", "@angular/common": "^5.0.0", "@angular/compiler": "^5.0.0", @@ -25,6 +26,7 @@ "@angular/router": "^5.0.0", "@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.5", "core-js": "^2.4.1", + "redux": "^3.7.2", "rxjs": "^5.5.2", "zone.js": "^0.8.14" }, diff --git a/web/angular/src/app/app.component.html b/web/angular/src/app/app.component.html index 3341b0e..2e2c5df 100644 --- a/web/angular/src/app/app.component.html +++ b/web/angular/src/app/app.component.html @@ -1,14 +1,7 @@
-
-
- One of three columns -
-
- One of three columns -
-
- One of three columns -
-
-
+

{{title}}

+ + + + \ No newline at end of file diff --git a/web/angular/src/app/app.component.spec.ts b/web/angular/src/app/app.component.spec.ts index bcbdf36..e00b3fe 100644 --- a/web/angular/src/app/app.component.spec.ts +++ b/web/angular/src/app/app.component.spec.ts @@ -13,15 +13,15 @@ describe('AppComponent', () => { const app = fixture.debugElement.componentInstance; expect(app).toBeTruthy(); })); - it(`should have as title 'app'`, async(() => { + it(`should have as title 'Maptology'`, async(() => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.debugElement.componentInstance; - expect(app.title).toEqual('app'); + expect(app.title).toEqual('Maptology'); })); it('should render title in a h1 tag', async(() => { const fixture = TestBed.createComponent(AppComponent); fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; - expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!'); + expect(compiled.querySelector('h1').textContent).toContain('Maptology'); })); }); diff --git a/web/angular/src/app/app.component.ts b/web/angular/src/app/app.component.ts index 7b0f672..7d37ef1 100644 --- a/web/angular/src/app/app.component.ts +++ b/web/angular/src/app/app.component.ts @@ -1,10 +1,19 @@ import { Component } from '@angular/core'; +import { OnInit } from '@angular/core/src/metadata/lifecycle_hooks'; +import { ConsoleService } from './console.service'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) -export class AppComponent { - title = 'app'; +export class AppComponent implements OnInit { + title = 'Maptology'; + + constructor(private consoleService: ConsoleService) { } + + ngOnInit() { + this.consoleService.log("App component initialized.") + } + } diff --git a/web/angular/src/app/app.module.ts b/web/angular/src/app/app.module.ts index f657163..4873dcf 100644 --- a/web/angular/src/app/app.module.ts +++ b/web/angular/src/app/app.module.ts @@ -1,16 +1,29 @@ import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; +import { InjectionToken } from '@angular/core'; +import {NgbModule} from '@ng-bootstrap/ng-bootstrap'; +import { HttpClientModule } from '@angular/common/http'; + +import { ApiClientService } from '../api/index' import { AppComponent } from './app.component'; +import { ConsoleComponent } from './console/console.component'; +import { ConsoleService } from './console.service'; +import { NoticesComponent } from './notices/notices.component'; @NgModule({ declarations: [ - AppComponent + AppComponent, + ConsoleComponent, + NoticesComponent ], imports: [ - BrowserModule + NgbModule.forRoot(), + BrowserModule, + HttpClientModule ], - providers: [], + // define the domain in ApiClientService see https://angular.io/guide/dependency-injection + providers: [{provide: "domain", useValue: "/api"}, ApiClientService, ConsoleService], bootstrap: [AppComponent] }) export class AppModule { } diff --git a/web/angular/src/app/console.service.spec.ts b/web/angular/src/app/console.service.spec.ts new file mode 100644 index 0000000..be11fa6 --- /dev/null +++ b/web/angular/src/app/console.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { ConsoleService } from './console.service'; + +describe('ConsoleService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [ConsoleService] + }); + }); + + it('should be created', inject([ConsoleService], (service: ConsoleService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/web/angular/src/app/console.service.ts b/web/angular/src/app/console.service.ts new file mode 100644 index 0000000..7519ea2 --- /dev/null +++ b/web/angular/src/app/console.service.ts @@ -0,0 +1,25 @@ +import { Injectable } from '@angular/core'; + +/** + * A console that can be used to log debug output + * throughout the application. + */ +@Injectable() +export class ConsoleService { + + messages: string[] = []; + + constructor() { } + + log(message: string) { + var date: Date = new Date(); + message = date.toISOString() + " " + message; + console.log(message); + this.messages.push(message); + } + + clear() { + this.messages = []; + } + +} diff --git a/web/angular/src/app/console/console.component.css b/web/angular/src/app/console/console.component.css new file mode 100644 index 0000000..e69de29 diff --git a/web/angular/src/app/console/console.component.html b/web/angular/src/app/console/console.component.html new file mode 100644 index 0000000..f8cf741 --- /dev/null +++ b/web/angular/src/app/console/console.component.html @@ -0,0 +1,31 @@ +
+
+
+
+

Console

+
+
+
+ + +
+
+
+
+
+
+
    +
  • {{message}}
  • +
+
+
+
\ No newline at end of file diff --git a/web/angular/src/app/console/console.component.spec.ts b/web/angular/src/app/console/console.component.spec.ts new file mode 100644 index 0000000..e8ebf2a --- /dev/null +++ b/web/angular/src/app/console/console.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ConsoleComponent } from './console.component'; + +describe('ConsoleComponent', () => { + let component: ConsoleComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ConsoleComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ConsoleComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/web/angular/src/app/console/console.component.ts b/web/angular/src/app/console/console.component.ts new file mode 100644 index 0000000..a7f7b97 --- /dev/null +++ b/web/angular/src/app/console/console.component.ts @@ -0,0 +1,32 @@ +import { Component, OnInit, ViewEncapsulation } from '@angular/core'; +import { ConsoleService } from '../console.service'; + +@Component({ + selector: 'app-console', + templateUrl: './console.component.html', + styleUrls: ['./console.component.css'], + encapsulation: ViewEncapsulation.None +}) +export class ConsoleComponent implements OnInit { + + public isCollapsed:boolean = true; + + constructor(private consoleService: ConsoleService) { } + + ngOnInit() { + this.consoleService.log("Console component initialized."); + } + + getMessages(): string[] { + return this.consoleService.messages; + } + + hasMessages(): boolean { + return this.consoleService.messages.length > 0; + } + + clearMessages(): void { + this.consoleService.clear(); + } + +} diff --git a/web/angular/src/app/notices/notices.component.css b/web/angular/src/app/notices/notices.component.css new file mode 100644 index 0000000..e69de29 diff --git a/web/angular/src/app/notices/notices.component.html b/web/angular/src/app/notices/notices.component.html new file mode 100644 index 0000000..92d8eb2 --- /dev/null +++ b/web/angular/src/app/notices/notices.component.html @@ -0,0 +1,37 @@ +
+
+

+ + Loading... +

+
+
+
+
+
+

{{ getNoticeTitle(notice) }}

+
+
{{ getNoticeBody(notice) }}
+
Updated on: {{ getNoticeTime(notice.modificationTime) }}
+
Created on: {{ getNoticeTime(notice.creationTime) }}
+
+
+
+
+
+
+ + + +
+
+
\ No newline at end of file diff --git a/web/angular/src/app/notices/notices.component.spec.ts b/web/angular/src/app/notices/notices.component.spec.ts new file mode 100644 index 0000000..acf5204 --- /dev/null +++ b/web/angular/src/app/notices/notices.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { NoticesComponent } from './notices.component'; + +describe('NoticesComponent', () => { + let component: NoticesComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ NoticesComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(NoticesComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/web/angular/src/app/notices/notices.component.ts b/web/angular/src/app/notices/notices.component.ts new file mode 100644 index 0000000..e1140e7 --- /dev/null +++ b/web/angular/src/app/notices/notices.component.ts @@ -0,0 +1,111 @@ +import { Component, OnInit, ViewEncapsulation } from '@angular/core'; +import { ConsoleService } from '../console.service'; +import { ApiClientService } from '../../api/index'; +import { NoticePage } from '../../api/models/noticepage.model'; +import { Notice } from '../../api/models/notice.model'; +import { Observable } from 'rxjs/Observable'; +import { Subject } from 'rxjs/Subject'; +import { HttpErrorResponse } from '@angular/common/http'; + +@Component({ + selector: 'app-notices', + templateUrl: './notices.component.html', + styleUrls: ['./notices.component.css'], + encapsulation: ViewEncapsulation.None +}) +export class NoticesComponent implements OnInit { + + public loading: boolean = false; + public notices: Subject = new Subject(); + public error: Subject = new Subject(); + + private page: NoticePage; + private offset: number = 0; + private size: number = 6; + + constructor(private consoleService: ConsoleService, private apiClientService: ApiClientService) { } + + ngOnInit() { + this.reloadPage(); + } + + getNoticeTitle(notice: Notice): string { + var message = notice.messages.find(msg => msg.language === "en"); + if (message == null) return ""; + else return message.title; + } + + getNoticeBody(notice: Notice): string { + var message = notice.messages.find(msg => msg.language === "en"); + if (message == null) return ""; + else return message.body; + } + + getNoticeTime(time: number): string { + var d = new Date(time); + return d.toLocaleString(); + } + + + hasReload(): boolean { + return (this.page == null && !this.loading); + } + + hasNext(): boolean { + if (this.page == null) return false; + else return this.offset + this.size < this.page.total; + } + + hasPrevious(): boolean { + if (this.page == null) return false; + else return this.offset > 0; + } + + nextPage(): void { + this.consoleService.log("Next page requested.") + this.offset = this.offset + this.size; + this.loadPage(this.offset, this.size); + } + + previousPage(): void { + this.consoleService.log("Previous page requested.") + this.offset = Math.max(0, this.offset - this.size); + this.loadPage(this.offset, this.size); + } + + reloadPage(): void { + this.consoleService.log("Reload page requested.") + this.loadPage(this.offset, this.size); + } + + loadPage(offset: number, size: number): void { + this.consoleService.log("Notice page with offset " + offset + " and size " + size + " requested."); + this.loading = true; + this.page = null; + this.error.next(null); + this.notices.next([]); + this.apiClientService.getNotices(offset, size).subscribe(data => { + this.consoleService.log("Notice page received."); + // slow down the request to debug the view + setTimeout(() => { + this.loading = false; + this.page = data.body; + this.notices.next(data.body.elements); + }, 3000); + + }, error => { + this.loading = false; + if (error instanceof HttpErrorResponse) { + let message = error.status + ": " + error.statusText; + this.consoleService.log("HttpError: " + message) + this.error.next(message); + } else { + this.consoleService.log("Unknown error."); + console.dir(error); // print it to the console + } + this.notices.next([]); + }); + + } + +} diff --git a/web/angular/src/index.html b/web/angular/src/index.html index 990c982..f8bc864 100644 --- a/web/angular/src/index.html +++ b/web/angular/src/index.html @@ -7,6 +7,7 @@ +