Skip to content

Commit ad9c7d5

Browse files
authored
Merge pull request #2 from Distributed-Noracle/develop
Develop
2 parents 167ba77 + 5f0b246 commit ad9c7d5

File tree

88 files changed

+1831
-481
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1831
-481
lines changed

.angular-cli.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"environmentSource": "environments/environment.ts",
2828
"environments": {
2929
"dev": "environments/environment.ts",
30-
"prod": "environments/environment.prod.ts"
30+
"prod": "environments/environment.prod.ts",
31+
"las2peer": "environments/environments.las2peer.ts"
3132
}
3233
}
3334
],

src/app/app.module.ts

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,51 @@
11
import {BrowserModule} from '@angular/platform-browser';
2-
import {CUSTOM_ELEMENTS_SCHEMA, NgModule} from '@angular/core';
2+
import {NgModule} from '@angular/core';
33
import {FormsModule} from '@angular/forms';
44
import {HttpModule} from '@angular/http';
5-
65
import {AppComponent} from './app.component';
76
import {GraphViewModule} from './graph-view/graph-view.module';
87
import {PolymerModule} from '@codebakery/origami';
9-
import {IronElementsModule, PaperElementsModule} from '@codebakery/origami/collections';
108
import {AuthModule, OidcSecurityService, OpenIDImplicitFlowConfiguration} from 'angular-auth-oidc-client';
119
import {RouterModule} from '@angular/router';
12-
import {LoginComponent} from './login/login.component';
1310
import {environment} from '../environments/environment';
14-
import {GraphViewPageComponent} from './graph-view/graph-view-page/graph-view-page.component';
1511
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
16-
import {FlexLayoutModule} from '@angular/flex-layout';
17-
import {MdButtonModule, MdMenuModule, MdToolbarModule} from '@angular/material';
18-
import {NavComponent} from './nav/nav.component';
19-
import {AuthGuardService} from './auth-guard/auth-guard.service';
12+
import {AuthGuardService} from './shared/auth-guard/auth-guard.service';
13+
import {NavigationModule} from './navigation/navigation.module';
14+
import {SharedModule} from './shared/shared.module';
15+
import {LoginModule} from './login/login.module';
16+
import {LoginPageComponent} from './login/login-page/login-page.component';
17+
import {GraphViewPageComponent} from './graph-view/graph-view-page/graph-view-page.component';
18+
import {WelcomePageComponent} from './login/welcome-page/welcome-page.component';
19+
import {SpaceModule} from './space/space.module';
20+
import {SubscribedSpacesOverviewComponent} from './space/subscribed-spaces-overview/subscribed-spaces-overview.component';
21+
import {CreateSpaceComponent} from './space/create-space/create-space.component';
22+
import {AfterLoginComponent} from './login/after-login/after-login.component';
2023

2124
@NgModule({
22-
declarations: [
23-
AppComponent,
24-
LoginComponent,
25-
NavComponent],
26-
schemas: [CUSTOM_ELEMENTS_SCHEMA],
25+
declarations: [AppComponent],
2726
imports: [
2827
BrowserModule,
2928
BrowserAnimationsModule,
3029
FormsModule,
3130
HttpModule,
32-
IronElementsModule,
33-
PaperElementsModule,
34-
FlexLayoutModule,
31+
SharedModule,
32+
NavigationModule,
33+
LoginModule,
34+
SpaceModule,
3535
GraphViewModule,
36-
MdMenuModule,
37-
MdToolbarModule,
38-
MdButtonModule,
3936
RouterModule.forRoot([
40-
{path: 'login', component: LoginComponent},
41-
{path: 'graph', component: GraphViewPageComponent, canActivate: [AuthGuardService]},
42-
{path: '**', redirectTo: 'login' }
37+
{path: 'welcome', component: WelcomePageComponent},
38+
{path: 'login', component: LoginPageComponent},
39+
{path: 'afterlogin', component: AfterLoginComponent},
40+
{path: 'myspaces', component: SubscribedSpacesOverviewComponent, canActivate: [AuthGuardService]},
41+
{path: 'spaces/create', component: CreateSpaceComponent, canActivate: [AuthGuardService]},
42+
{path: 'spaces/:spaceId', component: GraphViewPageComponent, canActivate: [AuthGuardService]},
43+
{path: '**', redirectTo: 'welcome'}
4344
]),
4445
PolymerModule.forRoot(),
4546
AuthModule.forRoot()
4647
],
47-
providers: [OidcSecurityService, AuthGuardService],
48+
providers: [],
4849
bootstrap: [AppComponent]
4950
})
5051
export class AppModule {
@@ -57,12 +58,13 @@ export class AppModule {
5758
openIDImplicitFlowConfiguration.response_type = 'id_token token';
5859
openIDImplicitFlowConfiguration.scope = 'openid email profile';
5960
openIDImplicitFlowConfiguration.post_logout_redirect_uri = environment.redirectUrl;
60-
openIDImplicitFlowConfiguration.startup_route = '/graph';
61+
openIDImplicitFlowConfiguration.startup_route = '/afterlogin';
6162
openIDImplicitFlowConfiguration.auto_userinfo = true;
6263
openIDImplicitFlowConfiguration.log_console_warning_active = !environment.production;
6364
openIDImplicitFlowConfiguration.log_console_debug_active = !environment.production;
6465
openIDImplicitFlowConfiguration.max_id_token_iat_offset_allowed_in_seconds = 10;
6566
openIDImplicitFlowConfiguration.override_well_known_configuration = false;
67+
openIDImplicitFlowConfiguration.silent_renew = false;
6668

6769
// TODO: configure
6870
openIDImplicitFlowConfiguration.forbidden_route = '/Forbidden';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<h1 md-dialog-title>{{data.title}}</h1>
2+
<div md-dialog-content>
3+
<p>{{data.message}}</p>
4+
<md-form-field>
5+
<textarea mdInput tabindex="1" [(ngModel)]="data.text"></textarea>
6+
</md-form-field>
7+
</div>
8+
<div md-dialog-actions>
9+
<button md-button [md-dialog-close]="data.text" tabindex="2">Ok</button>
10+
<button md-button (click)="onCancel()" tabindex="-1">Cancel</button>
11+
</div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { CreateQuestionDialogComponent } from './create-question-dialog.component';
4+
5+
describe('CreateQuestionDialogComponent', () => {
6+
let component: CreateQuestionDialogComponent;
7+
let fixture: ComponentFixture<CreateQuestionDialogComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ CreateQuestionDialogComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(CreateQuestionDialogComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {Component, Inject, OnInit} from '@angular/core';
2+
import {MD_DIALOG_DATA, MdDialogRef} from '@angular/material';
3+
4+
@Component({
5+
selector: 'dnor-create-question-dialog',
6+
templateUrl: './create-question-dialog.component.html',
7+
styleUrls: ['./create-question-dialog.component.css']
8+
})
9+
export class CreateQuestionDialogComponent implements OnInit {
10+
11+
constructor(public dialogRef: MdDialogRef<CreateQuestionDialogComponent>,
12+
@Inject(MD_DIALOG_DATA) public data: any) {
13+
}
14+
15+
ngOnInit() {
16+
}
17+
18+
onCancel(): void {
19+
this.dialogRef.close();
20+
}
21+
22+
}

src/app/graph-view/graph-view-page/graph-view-page.component.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
<!--<h1>Noracle Graph</h1>-->
22
<div #graphContainer>
3-
<dnor-graph-view [height]="height" [width]="width" [interactionMode]="interactionMode"></dnor-graph-view>
3+
<div *ngIf="subscriptionInProgress" fxLayout="column" fxLayoutAlign="space-around center">
4+
<p>Subscribing to space&hellip;</p>
5+
<md-spinner></md-spinner>
6+
</div>
7+
<dnor-graph-view *ngIf="!subscriptionInProgress"
8+
[spaceId]="spaceId"
9+
[selectedQuestions]="selectedQuestions" [height]="height" [width]="width"
10+
[interactionMode]="interactionMode"></dnor-graph-view>
411
</div>
512
<div #below>
6-
<md-radio-group fxLayout="row" fxLayoutGap="20px" [(ngModel)]="interactionMode">
13+
<md-radio-group *ngIf="!subscriptionInProgress"
14+
fxLayout="row" fxLayoutGap="20px" [(ngModel)]="interactionMode">
715
<md-radio-button *ngFor="let m of getInteractionModes()" [value]="m">
816
{{getInteractionModeLabel(m)}}
917
</md-radio-button>

src/app/graph-view/graph-view-page/graph-view-page.component.ts

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
1-
import {Component, ElementRef, HostListener, OnInit, ViewChild} from '@angular/core';
1+
import {Component, ElementRef, HostListener, OnDestroy, OnInit, ViewChild} from '@angular/core';
22
import {GraphInteractionMode} from '../graph-view/graph-data-model/graph-interaction-mode.enum';
3+
import {ActivatedRoute, Router} from '@angular/router';
4+
import {Subscription} from 'rxjs/Subscription';
5+
import {MyspacesService} from '../../shared/myspaces/myspaces.service';
36

47
@Component({
58
selector: 'dnor-graph-view-page',
69
templateUrl: './graph-view-page.component.html',
710
styleUrls: ['./graph-view-page.component.css']
811
})
9-
export class GraphViewPageComponent implements OnInit {
12+
export class GraphViewPageComponent implements OnInit, OnDestroy {
1013
@ViewChild('graphContainer')
1114
private graphContainer;
1215
@ViewChild('below')
1316
private below;
1417
private elementRef: ElementRef;
1518

16-
public interactionMode = GraphInteractionMode.SelectAndNavigate;
17-
public height = 600;
18-
public width = 800;
19+
private subscriptionInProgress = false;
20+
private interactionMode = GraphInteractionMode.SelectAndNavigate;
21+
private height = 600;
22+
private width = 800;
23+
private paramSubscription: Subscription;
24+
private queryParamSubscription: Subscription;
25+
private spaceId = '1';
26+
private selectedQuestions;
1927

2028
private adjustSize() {
2129
this.height = (window.innerHeight
@@ -24,14 +32,42 @@ export class GraphViewPageComponent implements OnInit {
2432
this.width = window.innerWidth * 0.9;
2533
}
2634

27-
constructor(elementRef: ElementRef) {
35+
constructor(elementRef: ElementRef, private activatedRoute: ActivatedRoute,
36+
private router: Router, private myspacesService: MyspacesService) {
2837
this.elementRef = elementRef;
2938
}
3039

3140
ngOnInit() {
41+
this.paramSubscription = this.activatedRoute.params.subscribe((params) => {
42+
this.spaceId = params['spaceId'];
43+
});
44+
this.queryParamSubscription = this.activatedRoute.queryParams.subscribe((queryParams) => {
45+
const pw = queryParams['pw'];
46+
if (pw !== undefined) {
47+
this.subscriptionInProgress = true;
48+
this.myspacesService.subscribeToSpace(this.spaceId, pw).then(() => {
49+
const qp = queryParams['sq'] !== undefined ? {sq: queryParams['sq']} : {};
50+
this.router.navigate([], {queryParams: qp, replaceUrl: true}).then(() =>
51+
this.subscriptionInProgress = false
52+
);
53+
});
54+
55+
}
56+
const q = queryParams['sq'];
57+
if (q === undefined) {
58+
this.selectedQuestions = [];
59+
} else {
60+
this.selectedQuestions = JSON.parse(q);
61+
}
62+
});
3263
this.adjustSize();
3364
}
3465

66+
ngOnDestroy() {
67+
this.paramSubscription.unsubscribe();
68+
this.queryParamSubscription.unsubscribe();
69+
}
70+
3571
@HostListener('window:resize', ['$event'])
3672
onWindowResize(event) {
3773
this.adjustSize();
Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
11
import {CUSTOM_ELEMENTS_SCHEMA, NgModule} from '@angular/core';
22
import {CommonModule} from '@angular/common';
33
import {GraphViewComponent} from './graph-view/graph-view.component';
4-
import {RestService} from './rest-service/rest.service';
5-
import {SpaceService} from './space.service';
6-
import {QuestionService} from './question.service';
7-
import {RelationService} from './relation.service';
84
import {D3Service} from 'd3-ng2-service';
95
import {GraphViewPageComponent} from './graph-view-page/graph-view-page.component';
10-
import {MdButtonModule, MdRadioModule} from '@angular/material';
6+
import {
7+
MdButtonModule, MdDialogModule, MdFormFieldModule, MdInputModule, MdProgressSpinnerModule,
8+
MdRadioModule, MdSnackBarModule
9+
} from '@angular/material';
1110
import {FormsModule} from '@angular/forms';
12-
import { GraphViewService } from './graph-view/graph-view.service';
11+
import {GraphViewService} from './graph-view/graph-view.service';
1312
import {FlexLayoutModule} from '@angular/flex-layout';
13+
import {SharedModule} from '../shared/shared.module';
14+
import {RelationPickerDialogComponent} from './relation-picker-dialog/relation-picker-dialog.component';
15+
import { CreateQuestionDialogComponent } from './create-question-dialog/create-question-dialog.component';
1416

1517
@NgModule({
1618
imports: [
1719
CommonModule,
1820
MdButtonModule,
1921
MdRadioModule,
22+
MdDialogModule,
23+
MdSnackBarModule,
24+
MdProgressSpinnerModule,
25+
MdFormFieldModule,
26+
MdInputModule,
2027
FormsModule,
21-
FlexLayoutModule
28+
FlexLayoutModule,
29+
SharedModule
2230
],
2331
schemas: [CUSTOM_ELEMENTS_SCHEMA],
24-
declarations: [GraphViewComponent, GraphViewPageComponent],
32+
declarations: [GraphViewComponent, GraphViewPageComponent, RelationPickerDialogComponent, CreateQuestionDialogComponent],
33+
bootstrap: [RelationPickerDialogComponent, CreateQuestionDialogComponent],
2534
exports: [GraphViewPageComponent],
26-
providers: [RestService, SpaceService, QuestionService, RelationService, D3Service, GraphViewService]
35+
providers: [D3Service, GraphViewService]
2736
})
2837
export class GraphViewModule {
2938
}

src/app/graph-view/graph-view/graph-data-model/edge.ts

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,50 @@
11
import {SimulationLinkDatum} from 'd3-force';
22
import {GraphNode} from './graph-node';
3+
import {Relation} from '../../../shared/rest-data-model/relation';
34

45
export class Edge implements SimulationLinkDatum<GraphNode> {
56

6-
public source: string | number | GraphNode;
7-
public target: string | number | GraphNode;
87
public isSelected = false;
98

10-
constructor(from: number | GraphNode, to: number | GraphNode) {
11-
this.source = from;
12-
this.target = to;
9+
constructor(public id: string,
10+
public source: string | number | GraphNode,
11+
public target: string | number | GraphNode, public relation: Relation) {
1312
}
1413

1514
getDistance() {
1615
return (this.source as GraphNode).radius + (this.target as GraphNode).radius + 10;
1716
}
1817

1918
draw(context: CanvasRenderingContext2D) {
19+
if (this.relation.directed) {
20+
this.drawDirected(context);
21+
} else {
22+
this.drawUndirected(context);
23+
}
24+
}
25+
26+
drawDirected(context: CanvasRenderingContext2D) {
27+
context.beginPath();
28+
const arrowSize = 3;
29+
const arrowGap = 5;
30+
const dx = (this.target as GraphNode).x - (this.source as GraphNode).x;
31+
const dy = (this.target as GraphNode).y - (this.source as GraphNode).y;
32+
const len = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
33+
const dx0 = dx / len;
34+
const dy0 = dy / len;
35+
for (let i = 0; i <= len; i += arrowGap) {
36+
const x = (this.source as GraphNode).x + i * dx0;
37+
const y = (this.source as GraphNode).y + i * dy0;
38+
context.moveTo(x - dx0 * arrowSize - dy0 * arrowSize, y - dy0 * arrowSize + dx0 * arrowSize);
39+
context.lineTo(x, y);
40+
context.lineTo(x - dx0 * arrowSize + dy0 * arrowSize, y - dy0 * arrowSize - dx0 * arrowSize);
41+
}
42+
context.lineWidth = this.isSelected ? 3 : 1;
43+
context.strokeStyle = '#000';
44+
context.stroke();
45+
}
46+
47+
drawUndirected(context: CanvasRenderingContext2D) {
2048
context.beginPath();
2149
context.moveTo((this.source as GraphNode).x, (this.source as GraphNode).y);
2250
context.lineTo((this.target as GraphNode).x, (this.target as GraphNode).y);

0 commit comments

Comments
 (0)