Skip to content

Commit

Permalink
Feature/floating sticky note (#30)
Browse files Browse the repository at this point in the history
* preparing floating sticky note logic

* feat(floating-sticky-note): floating-sticky-note implemented

Implementing a floating-sticky-note to add new notes
  • Loading branch information
andreasonny83 committed Jun 12, 2017
1 parent 4aad63d commit 980b6fe
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 79 deletions.
7 changes: 6 additions & 1 deletion src/app/app.component.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ const pkg = require('../../package.json');
describe('Online Board App', () => {
let utils: Utils;

beforeAll(() => {
// force a user log out
browser.driver.manage().deleteAllCookies();
});

beforeEach(() => {
utils = new Utils();

Expand All @@ -18,7 +23,7 @@ describe('Online Board App', () => {
});

it('should display a cookie policy notification', () => {
expect(element(by.css('cookie-law[name="onlineBaordCookieLaw"] .cookie-law-wrapper')).isDisplayed())
expect(element(by.css('cookie-law .cookie-law-wrapper')).isDisplayed())
.toBe(true);
});
});
8 changes: 8 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
MdIconModule,
MdDialogModule,
MdProgressSpinnerModule,
MdRadioModule,
} from '@angular/material';

import { AppComponent } from './app.component';
Expand All @@ -28,6 +29,8 @@ import { DialogResetEmailComponent } from './login/dialog-reset-email';
import { DashboardComponent } from './dashboard/dashboard.component';
import { BoardPageComponent } from './board-page/board-page.component';
import { DroppingCardComponent } from './dropping-card/dropping-card.component';
import { FloatingStickyNoteComponent } from './floating-sticky-note/floating-sticky-note.component';
import { ClickOutsideDirective } from './click-outside.directive';

import { FooterComponent } from './footer/footer.component';
import { BoardService } from './services/board.service';
Expand Down Expand Up @@ -58,8 +61,12 @@ const firebaseConfig = {
DroppingCardComponent,
FooterComponent,
DialogResetEmailComponent,
FloatingStickyNoteComponent,
// Pipes
Keyobject,
FilterColumn,
// Directives
ClickOutsideDirective,
],
imports: [
BrowserModule,
Expand All @@ -80,6 +87,7 @@ const firebaseConfig = {
MdIconModule,
MdProgressSpinnerModule,
MdDialogModule,
MdRadioModule,
// App Modules
HeaderModule,
AppRoutingModule,
Expand Down
33 changes: 3 additions & 30 deletions src/app/board-page/board-page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
*ngIf="!pageLoading"
(mouseup)="isDraggable = true"
(dragend)="onDrop($event)">

<h3 class="board-name">{{ (boardObj | async)?.name }}</h3>

<app-floating-sticky-note></app-floating-sticky-note>

<div class="item-list-container">
<div class="item-list"
*ngFor="let column of (boardObj | async)?.cols; let columnID = index">
Expand All @@ -14,36 +17,6 @@ <h3 class="board-name">{{ (boardObj | async)?.name }}</h3>
<md-icon>{{ column.icon }}</md-icon>
</div>

<md-card [style.background]="column.color"
(mouseenter)="elevateCard(columnID)"
(mouseleave)="removeElevation(columnID)"
class="note unpinned-note mat-elevation-z10"
[class.mat-elevation-z18]="isElevated(columnID)">
<form (ngSubmit)="pushPost(columnID)"
class="form">

<md-input-container class="full-width">
<textarea mdInput
#newItem
class="new-item"
placeholder="Write your feedback"
mdTextareaAutosize
[(ngModel)]="newItems[columnID]"
name="item"></textarea>
</md-input-container>

<button md-button
type="submit"
name="new-item"
class="pin-me-btn">
Pin me
<img class="pin-icon"
src="../../assets/images/pushpin.png"
alt="Pin me">
</button>
</form>
</md-card>

<md-card *ngFor="let post of (boardObj | async).posts | keyobject | filterColumn: columnID;
let i = index;"
[style.background]="column.color"
Expand Down
13 changes: 0 additions & 13 deletions src/app/board-page/board-page.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@
resize: none;
}

.unpinned-note .new-item {
font-size: 28px;
}

.pinned-note {
cursor: move;
cursor: grab;
Expand Down Expand Up @@ -100,12 +96,3 @@
font-size: 16px;
opacity: 0.6;
}

.unpinned-note .pin-me-btn {
background-color: rgba(0, 0, 0, 0.08);
font-size: 30px;
}

.unpinned-note .pin-me-btn .pin-icon {
height: 30px;
}
34 changes: 0 additions & 34 deletions src/app/board-page/board-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,40 +53,6 @@ export class BoardPageComponent implements OnInit, OnDestroy {
});
}

public elevateCard(i: number): void {
this.cardElevations[i] = true;
}

public isElevated(i: number): boolean {
return this.cardElevations[i];
}

public removeElevation(i: number): void {
this.cardElevations[i] = false;
}

public pushPost(column: number): void {
const authorName = this.fireBase.userInfo.name;
const authorUID = this.fireBase.userInfo.uid;

this.boardObj.$ref.ref
.child('posts')
.push({
val: this.newItems[column],
author: authorName,
authorUID: authorUID,
col: column,
})
.catch(err => {
this.snackBar.open(`
Please, make sure the feedback is not empty
and you are a collaborator on this board.`,
null, { duration: 6000 });
});

this.newItems[column] = '';
}

public updatePost(post: any, postRef): void {
this.boardObj.$ref.ref
.child(`posts/${post.key}`)
Expand Down
24 changes: 24 additions & 0 deletions src/app/click-outside.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {Directive, ElementRef, Output, EventEmitter, HostListener} from '@angular/core';

@Directive({
selector: '[clickOutside]'
})
export class ClickOutsideDirective {
@Output()
public clickOutside = new EventEmitter<MouseEvent>();

@HostListener('document:click', ['$event', '$event.target'])
public onClick(event: MouseEvent, targetElement: HTMLElement): void {
if (!targetElement) {
return;
}

const clickedInside = this._elementRef.nativeElement.contains(targetElement);

if (!clickedInside) {
this.clickOutside.emit(event);
}
}

constructor(private _elementRef: ElementRef) { }
}
79 changes: 79 additions & 0 deletions src/app/floating-sticky-note/floating-sticky-note.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { FirebaseService, FirebaseObjectObservable } from '../../firebase';
import { BoardService } from '../services/board.service';
import { MdSnackBar } from '@angular/material';

@Component ({
selector:
'app-floating-sticky-note',
templateUrl: './floating-sticky-note.html',
styleUrls: ['./floating-sticky-note.scss'],
})
export class FloatingStickyNoteComponent implements OnInit {
@ViewChild('textArea')
public textArea;

public active: boolean;
public stickyForm: FormGroup;

private boardObj: FirebaseObjectObservable<any>;

constructor(
private fb: FormBuilder,
private fireBase: FirebaseService,
private boardService: BoardService,
private snackBar: MdSnackBar,
) {
this.stickyForm = this.fb.group({
chose: ['', Validators.required ],
newPost: ['', Validators.required ],
});
}

ngOnInit() {
this.boardObj = this.fireBase.getBoardObject(this.boardService.currentBoard.uid);
}

focus(): void {
if (!!this.active) {
return;
}

setTimeout(() => {
this.textArea.nativeElement.focus();
this.stickyForm.controls['newPost'].setValue('');
}, 0);
}

public pushPost(): void {
const authorName = this.fireBase.userInfo.name;
const authorUID = this.fireBase.userInfo.uid;

if (this.stickyForm.invalid) {
this.snackBar.open(`
Please, make sure the feedback is not empty
and you have selected a column in where to push this message to.`,
null, { duration: 6000 });

return;
}

this.boardObj.$ref.ref
.child('posts')
.push({
val: this.stickyForm.controls['newPost'].value,
author: authorName,
authorUID: authorUID,
col: this.stickyForm.controls['chose'].value.pos,
})
.then(() => this.active = false)
.catch(err => {
this.snackBar.open(`
Error. Only collaborators have the rights to write new feedbacks.`,
null, { duration: 6000 });
});

this.stickyForm.reset();
}
}
56 changes: 56 additions & 0 deletions src/app/floating-sticky-note/floating-sticky-note.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<div class="floating-sticky-note-overlay-container"
[class.active]="active">

<md-card class="note unpinned-note mat-elevation-z10"
(click)="active = true"
(clickOutside)="active = false">
<form class="form"
novalidate
[formGroup]="stickyForm"
(ngSubmit)="pushPost()">

<md-card-content (click)="focus()">
<div class="placeholder"
[hidden]="active">
<span>
Write your feedback
</span>
</div>

<md-input-container class="full-width"
[hidden]="!active">
<textarea mdInput
mdTextareaAutosize
#textArea
class="new-item"
formControlName="newPost"
placeholder="Write your feedback"
name="item"></textarea>
</md-input-container>

<md-radio-group class="radio-group"
[hidden]="!active"
formControlName="chose">
<md-radio-button *ngFor="let column of (boardObj | async)?.cols"
[value]="column">{{ column.title }}</md-radio-button>
</md-radio-group>

</md-card-content>

<md-card-actions align="end" [hidden]="!active">

<button md-button
type="submit"
name="new-item"
[disabled]="!stickyForm.valid"
class="pin-me-btn">
Pin me
<img class="pin-icon"
src="../../assets/images/pushpin.png"
alt="Pin me">
</button>
</md-card-actions>
</form>
</md-card>

</div>
Loading

0 comments on commit 980b6fe

Please sign in to comment.