Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(context): Base layout for the context editor and a few changes i… #152

Merged
merged 4 commits into from
Mar 3, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@angular/compiler": "^2.4.5",
"@angular/compiler-cli": "^2.4.5",
"@angular/core": "^2.4.5",
"@angular/forms": "^2.4.5",
"@angular/forms": "^2.4.9",
"@angular/http": "^2.4.5",
"@angular/material": "^2.0.0-beta.1",
"@angular/platform-browser": "^2.4.5",
Expand Down
35 changes: 23 additions & 12 deletions src/app/app.component.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@require '../css/theme.styl';
@require '../css/media.styl';

:host, main {
width: 100%;
Expand All @@ -11,30 +12,40 @@ main {
transition: 0.5s;
}

:host >>> .mat-input-element {
padding: 0 $igo-padding;
}

:host >>> .mat-input-wrapper {
padding: 0;
:host >>> .mat-icon {
color: $igo-primary-color;
}

:host >>> .mat-input-placeholder-wrapper {
top: 10px;
left: $igo-padding;
right: $igo-padding;
padding: 0;
:host >>> .mat-input-element {
padding: 0 $igo-padding;
}

:host >>> .mat-input-placeholder {
font-style: italic;
color: $igo-border-color;
}

:host >>> .mat-input-underline {
border-color: $igo-border-color;
}

:host >>> md-input-container {
width: 100%;
}

:host >>> md-radio-group.horizontal {
display: block;
text-align: center;

+media(mobile) {
text-align: inherit;
}
}

:host >>> md-radio-group.horizontal md-radio-button {
padding: 0 8px;
}


/*--- Spinner ---*/
igo-spinner {
position: absolute;
Expand Down
5 changes: 2 additions & 3 deletions src/app/context/context-editor/context-editor.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<p>
context-editor works!
</p>
<igo-context-form [context]="context">
</igo-context-form>
22 changes: 17 additions & 5 deletions src/app/context/context-editor/context-editor.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { async, TestBed } from '@angular/core/testing';
// import { ComponentFixture } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';

import { TestModule } from '../../test.module';

import { ToolService } from '../../tool/shared/tool.service';

import { ContextService } from '../shared/context.service';
import { ContextEditorComponent } from './context-editor.component';
import { ContextFormComponent } from '../context-form/context-form.component';

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

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
ReactiveFormsModule,
TestModule
],
declarations: [ ContextEditorComponent ],
declarations: [
ContextEditorComponent,
ContextFormComponent
],
providers: [
ContextService,
ToolService
Expand All @@ -25,13 +32,18 @@ describe('ContextEditorComponent', () => {
.compileComponents();
}));

/*
beforeEach(() => {
fixture = TestBed.createComponent(ContextEditorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
component.context = {
title: 'foo',
uri: 'bar'
};
expect(component).toBeTruthy();
});
*/
});
6 changes: 2 additions & 4 deletions src/app/context/context-editor/context-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ export class ContextEditorComponent implements ToolComponent, OnInit {

ngOnInit() {
this.store
.select(s => s.activeContext)
.subscribe((context: Context) => {
this.context = context;
});
.select(s => s.editedContext)
.subscribe((context: Context) => this.context = context);
}

updateContext() {
Expand Down
63 changes: 63 additions & 0 deletions src/app/context/context-form/context-form.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<form [formGroup]="form" novalidate>

<fieldset>
<div>
<md-input-container>
<input
mdInput
formControlName="title"
placeholder="{{'Title' | translate}}">
</md-input-container>
<small
class="igo-form-inline-error"
[hidden]="title.valid || (title.pristine && !submitted)">
{{'contextTitleValidation' | translate}}
</small>
</div>

<div>
<md-input-container>
<input
mdInput
formControlName="description"
placeholder="{{'Description' | translate}}">
</md-input-container>
</div>

<div>
<md-input-container>
<input
readonly
mdInput
placeholder="{{'Alias' | translate}}"
value="{{context.uri}}">
</md-input-container>
</div>

<div class="igo-input-container">
<md-radio-group formControlName="scope" class="horizontal">
<md-radio-button value="public">{{'Public' | translate}}</md-radio-button>
<md-radio-button value="protected">{{'Protected' | translate}}</md-radio-button>
<md-radio-button value="private">{{'Private' | translate}}</md-radio-button>
</md-radio-group>
</div>
</fieldset>

<div class="igo-form-button-group">
<button md-raised-button [mdMenuTriggerFor]="saveMenu">
{{'Save' | translate}}
</button>

<md-menu #saveMenu="mdMenu">
<button md-menu-item (click)="saveProperties(form.value, form.valid)">
<md-icon>settings</md-icon>
<span>{{'Properties' | translate}}</span>
</button>
<button md-menu-item (click)="savePropertiesAndMap(form.value, form.valid)">
<md-icon>map</md-icon>
<span>{{'Properties & Map' | translate}}</span>
</button>
</md-menu>
</div>

</form>
40 changes: 40 additions & 0 deletions src/app/context/context-form/context-form.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { async, TestBed } from '@angular/core/testing';
// import { ComponentFixture } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';

import { TestModule } from '../../test.module';
import { SharedModule } from '../../shared/shared.module';

import { ContextFormComponent } from './context-form.component';

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

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
ReactiveFormsModule,
TestModule,
SharedModule
],
declarations: [ ContextFormComponent ]
})
.compileComponents();
}));

/*
beforeEach(() => {
fixture = TestBed.createComponent(ContextFormComponent);
component = fixture.componentInstance;
});

it('should create', () => {
component.context = {
title: 'foo',
uri: 'bar'
};
expect(component).toBeTruthy();
});
*/
});
Empty file.
67 changes: 67 additions & 0 deletions src/app/context/context-form/context-form.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Component, OnInit, Input } from '@angular/core';
import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms';

import { Context } from '../shared/context.interface';

@Component({
selector: 'igo-context-form',
templateUrl: './context-form.component.html',
styleUrls: ['./context-form.component.styl']
})
export class ContextFormComponent implements OnInit {

@Input() context: Context;

form: FormGroup;
submitted: boolean;

get title () {
return (<FormControl>this.form.controls['title']);
}

get description () {
return (<FormControl>this.form.controls['description']);
}

get uri () {
return (<FormControl>this.form.controls['uri']);
}

get scope () {
return (<FormControl>this.form.controls['scope']);
}

constructor(private formBuilder: FormBuilder) { }

ngOnInit() {
this.form = this.formBuilder.group({
title: ['', [
Validators.required,
Validators.minLength(3)
]],
description: '',
uri: '',
scope: '',
});

this.populate();
}

saveProperties(data: Context, isValid: boolean) {
this.submitted = true;
console.log(data, isValid);
}

savePropertiesAndMap(data: Context, isValid: boolean) {
this.submitted = true;
console.log(data, isValid);
}

private populate() {
this.title.setValue(this.context.title, {onlySelf: true});
this.description.setValue(this.context.description, {onlySelf: true});
this.uri.setValue(this.context.uri, {onlySelf: true});
this.scope.setValue(this.context.scope, {onlySelf: true});
}

}
2 changes: 1 addition & 1 deletion src/app/context/context-list/context-list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<igo-context-list-item
igoListItem
tabindex="{{i}}"
[selected]="selectedContext && selectedContext.name === context.name"
[selected]="selectedContext && selectedContext.uri === context.uri"
[context]="context"
[edition]="edition"
(selectItem)="selectContext(context)"
Expand Down
13 changes: 5 additions & 8 deletions src/app/context/context-list/context-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,19 @@ export class ContextListComponent implements ToolComponent, OnInit {
ngOnInit() {
this.store
.select(s => s.tools)
.subscribe((tools: Tool[]) => {
this.editTool = tools.find(t => t.name === 'contextEditor');
});
.subscribe((tools: Tool[]) =>
this.editTool = tools.find(t => t.name === 'contextEditor'));

this.store
.select(s => s.activeContext)
.subscribe((context: Context) => {
this.selectedContext = context;
});
.subscribe((context: Context) => this.selectedContext = context);

this.contexts = this.contextService.getContexts();
}

selectContext(context: Context) {
if (context.name !== this.selectedContext.name) {
this.contextService.loadContext(context.name);
if (context.uri !== this.selectedContext.uri) {
this.contextService.loadContext(context.uri);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/app/context/context.module.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';

import { SharedModule } from '../shared/shared.module';

import { ContextListComponent } from './context-list/context-list.component';
import { ContextListItemComponent } from './context-list-item/context-list-item.component';
import { ContextService } from './shared/context.service';
import { ContextEditorComponent } from './context-editor/context-editor.component';
import { ContextFormComponent } from './context-form/context-form.component';


@NgModule({
imports: [
SharedModule
SharedModule,
ReactiveFormsModule
],
declarations: [
ContextListComponent,
ContextListItemComponent,
ContextEditorComponent
ContextEditorComponent,
ContextFormComponent
],
entryComponents: [
ContextEditorComponent,
Expand Down
4 changes: 3 additions & 1 deletion src/app/context/shared/context.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export interface Context {
title: string;
name: string;
uri: string;
scope?: 'public' | 'protected' | 'private';
description?: string;
icon?: string;
}
Loading