Skip to content

Commit

Permalink
Merge pull request #2 from thoughtworks/conversation
Browse files Browse the repository at this point in the history
Conversation
  • Loading branch information
zigolab authored Jul 5, 2019
2 parents a9ebe46 + bf40e0f commit 3ac5f83
Show file tree
Hide file tree
Showing 47 changed files with 1,949 additions and 264 deletions.
5 changes: 4 additions & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fileignoreconfig:
checksum: 510ff54745a0315fdaa5de0cf6923cc4e30081789e358120baf277f8cd1b5379
ignore_detectors: []
- filename: src/app/services/backend.service.spec.ts
checksum: dcf98ba54329a81de976728ca53eb91cbf13ac54a659422bdf0571ef237acf31
checksum: cac6925ede89879ba601e3e08bc3e9aa8c58c61863eb82f914c2829a1e5c0de1
ignore_detectors: []
- filename: docs/images/vote_process.gif
checksum: c3a82314b7db3029e5dd9b4226bde884f472561112b4287b5193eeeab1a7cf75
Expand All @@ -34,6 +34,9 @@ fileignoreconfig:
- filename: config/byor.sh.sample
checksum: f6ea581aca0260b7f9d098b5715cfaed8702e3ff4de3b2e8f9e4429db9022982
ignore_detectors: []
- filename: src/app/modules/login/login-voting-event/login-voting-event.component.ts
checksum: c56211684d1af6785d67fe6deda91af2b405037c80161090561eb388c642e5e7
ignore_detectors: []
- filename: .make/cd/deploy_aws.sh
checksum: 2740b006c659977adb8595efe4c3802f14e093075f03c7a84552af96fd4e09b1
ignore_detectors: []
Expand Down
23 changes: 19 additions & 4 deletions src/app/app-routes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Routes } from '@angular/router';
import { LoginComponent } from './modules/login/login.component';
import { ErrorComponent } from './components/error/error.component';
import { VotingEventSelectComponent } from './components/voting-event-select/voting-event-select.component';
import { LoginVotingEventComponent } from './modules/login/login-voting-event/login-voting-event.component';
import { NicknameComponent } from './modules/login/nickname/nickname.component';

export const appRoutes: Routes = [
{
Expand All @@ -17,11 +20,23 @@ export const appRoutes: Routes = [
loadChildren: './modules/admin/admin.module#AdminModule'
},
{
path: 'vote',
loadChildren: './modules/vote/vote.module#VoteModule'
path: 'selectVotingEvent',
component: VotingEventSelectComponent
},
{
path: 'login-voting-event',
component: LoginVotingEventComponent
},
{
path: '**',
redirectTo: 'vote',
path: 'nickname',
component: NicknameComponent
},
{
path: 'vote',
loadChildren: './modules/vote/vote.module#VoteModule'
}
// {
// path: '**',
// redirectTo: 'vote',
// },
];
44 changes: 44 additions & 0 deletions src/app/app-session.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Injectable } from '@angular/core';
import { VotingEvent } from 'src/app/models/voting-event';
import { Technology } from './models/technology';
import { Credentials } from './models/credentials';

@Injectable({
providedIn: 'root'
})
export class AppSessionService {
private votingEvents: VotingEvent[];
private selectedVotingEvent: VotingEvent;
private selectedTechnology: Technology;
private credentials: Credentials;

constructor() {}

getVotingEvents() {
return this.votingEvents;
}
setVotingEvents(votingEvents: VotingEvent[]) {
this.votingEvents = votingEvents;
}

getSelectedVotingEvent() {
return this.selectedVotingEvent;
}
setSelectedVotingEvent(votingEvent: VotingEvent) {
this.selectedVotingEvent = votingEvent;
}

getSelectedTechnology() {
return this.selectedTechnology;
}
setSelectedTechnology(technology: Technology) {
this.selectedTechnology = technology;
}

getCredentials() {
return this.credentials;
}
setCredentials(credentials: Credentials) {
this.credentials = credentials;
}
}
14 changes: 5 additions & 9 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TestBed, async } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
import { HeaderComponent } from './components/header/header.component';
import { ConfigurationService } from './services/configuration.service';
Expand All @@ -8,18 +9,14 @@ describe('AppComponent', () => {
beforeEach(async(() => {
const configurationServiceSpy: jasmine.SpyObj<ConfigurationService> = jasmine.createSpyObj('ConfigurationService', ['toString']);
TestBed.configureTestingModule({
imports: [
RouterTestingModule
],
declarations: [
AppComponent, HeaderComponent
],
imports: [RouterTestingModule, HttpClientModule],
declarations: [AppComponent, HeaderComponent],
providers: [
{
provide: ConfigurationService,
useValue: configurationServiceSpy
},
],
}
]
}).compileComponents();
}));

Expand All @@ -28,5 +25,4 @@ describe('AppComponent', () => {
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
});

});
49 changes: 46 additions & 3 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,59 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { version } from './version';
import { Router } from '@angular/router';
import { BackendService } from './services/backend.service';
import { ErrorService } from './services/error.service';
import { AppSessionService } from './app-session.service';
import { getIdentificationRoute } from './utils/voting-event-flow.util';
import { map, tap } from 'rxjs/operators';
import { ConfigurationService } from './services/configuration.service';

@Component({
selector: 'byor-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
export class AppComponent implements OnInit {
version = version;

constructor(private router: Router) {}
constructor(
private router: Router,
private backend: BackendService,
public errorService: ErrorService,
private appSession: AppSessionService,
private configurationService: ConfigurationService
) {}

ngOnInit() {
this.configurationService
.defaultConfiguration()
.pipe(
tap((config) => {
if (config.enableVotingEventFlow) {
this.backend
.getVotingEvents()
.pipe(map((votingEvents) => votingEvents.filter((ve) => ve.status === 'open')))
.subscribe((votingEvents) => {
if (!votingEvents || votingEvents.length === 0) {
this.errorService.setError(new Error('There are no Voting Events open'));
this.router.navigate(['error']);
} else if (votingEvents.length === 1) {
const votingEvent = votingEvents[0];
this.appSession.setSelectedVotingEvent(votingEvent);
const route = getIdentificationRoute(votingEvent);
this.router.navigate([route]);
} else {
this.appSession.setVotingEvents(votingEvents);
this.router.navigate(['selectVotingEvent']);
}
});
} else {
this.router.navigate(['vote']);
}
})
)
.subscribe();
}

goToAdminPage() {
this.router.navigate(['admin']);
Expand Down
7 changes: 2 additions & 5 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ import { HttpErrorHandler } from './shared/http-error-handler/http-error-handler
import { EventsService } from './services/events.service';
import { environment } from '../environments/environment';
import { getToken } from './utils/get-token';

// export function getToken() {
// return localStorage.getItem('access_token');
// }
import { VotingEventSelectComponent } from './components/voting-event-select/voting-event-select.component';

export function apiDomain() {
return [new URL(environment.serviceUrl).hostname + ':' + new URL(environment.serviceUrl).port];
Expand All @@ -34,7 +31,7 @@ export function jwtOptionsFactory() {
}

@NgModule({
declarations: [AppComponent, ErrorComponent, HeaderComponent],
declarations: [AppComponent, ErrorComponent, HeaderComponent, VotingEventSelectComponent],
imports: [
RouterModule.forRoot(appRoutes),
BrowserModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div class="selection-section">
<div class="event-selection">
<mat-form-field>
<mat-select #eventSelect placeholder="Choose a voting event" id="eventSelectEl" (selectionChange)="eventSelected(eventSelect)">
<mat-option *ngFor="let votingEvent of appSession.getVotingEvents()" [value]="votingEvent.name">
{{votingEvent.name}}
</mat-option>
</mat-select>
</mat-form-field>
</div>
</div>

<div class="select-actions">
<button #selectButton mat-flat-button color="accent" [class.button-disabled]="!votingEventName"
[class.button-enabled]="votingEventName" [disabled]="!votingEventName" (click)="goToIdentification()">
<span class="button-text"> Select Event </span>
</button>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@import "../../styles/abstracts/mixins";

$selection-sections-max-width: 480px;

.selection-section {
margin: 1.3rem auto;
padding: 0 1.3rem;
max-width: $selection-sections-max-width;

.event-selection {
display: block;
}

mat-form-field {
width: 100%;
}

.voter {
margin-bottom: 2rem;

.voter-input {
width: 100%;
@include byor-input;
}

label {
display: block;
margin-bottom: .3rem;
}
}

.button-disabled {
border: none;
}

.button-text {
color: #ffffff;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AppMaterialModule } from '../../app-material.module';
import { RouterTestingModule } from '@angular/router/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { VotingEventSelectComponent } from './voting-event-select.component';
import { AppSessionService } from 'src/app/app-session.service';
import { VotingEvent } from 'src/app/models/voting-event';

class MockAppSessionService {
private votingEvents: VotingEvent[];

constructor() {
this.votingEvents = [{ _id: '123', name: 'an event', status: 'open', creationTS: 'abc' }];
}

getVotingEvents() {
return this.votingEvents;
}
}

describe('VotingEventSelectComponent', () => {
let component: VotingEventSelectComponent;
let fixture: ComponentFixture<VotingEventSelectComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [AppMaterialModule, RouterTestingModule, BrowserAnimationsModule],
declarations: [VotingEventSelectComponent],
providers: [{ provide: AppSessionService, useClass: MockAppSessionService }]
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(VotingEventSelectComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Component, OnInit } from '@angular/core';
import { AppSessionService } from '../../app-session.service';
import { VotingEvent } from 'src/app/models/voting-event';
import { MatSelect } from '@angular/material/select';
import { getIdentificationRoute } from 'src/app/utils/voting-event-flow.util';
import { Router } from '@angular/router';

@Component({
selector: 'byor-voting-event-select',
templateUrl: './voting-event-select.component.html',
styleUrls: ['./voting-event-select.component.scss']
})
export class VotingEventSelectComponent implements OnInit {
votingEventName: string;

constructor(public appSession: AppSessionService, private router: Router) {}

ngOnInit() {}

eventSelected(eventSelect: MatSelect) {
this.votingEventName = eventSelect.value;
}

goToIdentification() {
const votingEvent = this.appSession.getVotingEvents().find((ve) => ve.name === this.votingEventName);
this.appSession.setSelectedVotingEvent(votingEvent);
const route = getIdentificationRoute(votingEvent);
this.router.navigate([route]);
}
}
4 changes: 4 additions & 0 deletions src/app/models/credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Credentials {
userId?: string;
nickname?: string;
}
3 changes: 3 additions & 0 deletions src/app/models/technology.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Comment } from './comment';

export interface Technology {
_id?: string;
id?: string;
Expand All @@ -7,4 +9,5 @@ export interface Technology {
description: string;
imageFile?: string;
forRevote?: boolean;
comments?: Comment[];
}
1 change: 1 addition & 0 deletions src/app/models/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Technology } from './technology';
import { Comment } from './comment';

export interface Vote {
_id?: string;
ring: string;
technology: Technology;
eventRound?: any;
Expand Down
6 changes: 6 additions & 0 deletions src/app/models/voting-event-flow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { VotingEventStep } from './voting-event-step';
import { VotingEvent } from './voting-event';

export interface VotingEventFlow {
steps: VotingEventStep[];
}
Loading

0 comments on commit 3ac5f83

Please sign in to comment.