Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
csfalcione committed Jan 7, 2018
2 parents 45a50c1 + 84d4676 commit 90d29f6
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/app/auth/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
[(ngModel)]="model.rememberMe" name="remember">
<label for="inputCheckbox">Remember me</label>
</div>
<a class="float-right" href="forgot-password.html">Forgot password?</a>
<!--<a class="float-right" href="forgot-password.html">Forgot password?</a>-->
</div>
<button type="submit" class="btn btn-primary btn-block btn-lg mt-40"
[disabled]="!loginForm.form.valid">Sign in</button>
Expand Down
2 changes: 1 addition & 1 deletion src/app/auth/register/register.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
[(ngModel)]="model.rememberMe" name="remember">
<label for="inputCheckbox">Remember me</label>
</div>
<a class="float-right" href="javascript:void(0)">Forgot password?</a>
<!--<a class="float-right" href="javascript:void(0)">Forgot password?</a>-->
</div>
<button type="submit" class="btn btn-primary btn-block btn-lg mt-40"
[disabled]="!loginForm.form.valid">Register</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,6 @@ <h2> Validating Invitation... </h2>
<h3 class="panel-title">
<i class="icon wb-book"></i>
<a [routerLink]="['/projects', invitation.project.id]">{{invitation.project.name}}</a></h3>
<div class="panel-actions panel-actions-keep">
<div class="dropdown">
<a class="panel-action" id="examplePanelDropdown" data-toggle="dropdown" href="#"
role="button"><i class="icon wb-more-vertical"></i></a>
<div class="dropdown-menu dropdown-menu-bullet dropdown-menu-right" aria-labelledby="examplePanelDropdown"
role="menu">
<a (click)="editProject(invitation.project, modal)" class="dropdown-item" href="javascript:void(0)" role="menuitem">
<i class="icon wb-settings" aria-hidden="true"></i> Edit</a>
</div>
</div>
</div>
</div>
<div class="panel-body">
<p>{{invitation.project.description}}</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,6 @@ <h2> Validating Invitation... </h2>
<h3 class="panel-title">
<i class="icon wb-book"></i>
<a [routerLink]="['/projects', invitation.project.id]">{{invitation.project.name}}</a></h3>
<div class="panel-actions panel-actions-keep">
<div class="dropdown">
<a class="panel-action" id="examplePanelDropdown" data-toggle="dropdown" href="#"
role="button"><i class="icon wb-more-vertical"></i></a>
<div class="dropdown-menu dropdown-menu-bullet dropdown-menu-right" aria-labelledby="examplePanelDropdown"
role="menu">
<a (click)="editProject(invitation.project, modal)" class="dropdown-item" href="javascript:void(0)" role="menuitem">
<i class="icon wb-settings" aria-hidden="true"></i> Edit</a>
</div>
</div>
</div>
</div>
<div class="panel-body">
<p>{{invitation.project.description}}</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#questionTree
(nodeDoubleClicked)="treeNodeDoubleClicked($event)"
[allowDrag]="true"
[allowDrop]="allowDrop"
(nodeMoved)="treeMove($event)"
[rootCategory]="form.root_category">
</app-question-tree>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ export class CodeBookTreeComponent {
treeEdit(node: AppTreeNode){
switch(node.type){
case AppNodeType.category:
this.activeFormCategory = this.questionTree.lookupInForm(this.activeNode.id);
this.activeFormCategory = this.questionTree.sourceMap['categories'][node.id];
return this.modal = this.ms.open(this.categoryModalContent);

case AppNodeType.question:
this.activeFormQuestion = this.questionTree.lookupInForm(this.activeNode.id);
this.activeFormQuestion = this.questionTree.sourceMap['questions'][node.id];
return this.modal = this.ms.open(this.questionModalContent);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h2 class="mt-0">{{channel.display_name}}</h2>
<p><mat-progress-bar mode="indeterminate" *ngIf="loading > 0"></mat-progress-bar></p>

<app-comments *ngFor="let comment of displayComments"
[userID]="comment.user.id"
[userID]="user.id"
(onReply)="onReply($event)"
(onEdit)="onEdit($event)"
(onDelete)="onDelete($event)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export class QuestionBuilderComponent implements OnInit {
let initialState: any = this.question;
if(!initialState) initialState = defaultModel;

initialState.options = initialState.options || [];
initialState.accepts = initialState.accepts || [];
initialState.options = initialState.options.map( opt => opt.txt );
initialState.accepts = initialState.options.map( opt => opt.txt );

Expand Down
16 changes: 14 additions & 2 deletions src/app/shared/components/question-tree/dataMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@ import {AppQuestion} from '../../../models/AppQuestion';
import {AppCategory} from '../../../models/AppCategory';
import {AppNodeType, AppTreeNode} from './dataModel';

export function mapToTreeNodes(rootCategory: AppCategory): AppTreeNode[] {
let sourceMap;

export function mapToTreeNodes(rootCategory: AppCategory) {
sourceMap = {
'categories': {},
'questions': {}
};

let root = mapCategory(rootCategory);
root.isRoot = true;
return [root];
return {
nodes: [root],
sourceMap: sourceMap
};
}

function mapCategory(category: AppCategory): AppTreeNode {
let children = [];
category.questions.map( question => children.push(mapQuestion(question)));
category.children.map( _category => children.push(mapCategory(_category)));

sourceMap['categories'][category.id] = category;
return new AppTreeNode({
id: category.id,
type: AppNodeType.category,
Expand All @@ -22,6 +33,7 @@ function mapCategory(category: AppCategory): AppTreeNode {
}

function mapQuestion(question: AppQuestion){
sourceMap['questions'][question.id] = question;
return new AppTreeNode({
id: question.id,
type: AppNodeType.question,
Expand Down
28 changes: 7 additions & 21 deletions src/app/shared/components/question-tree/question-tree.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Component, EventEmitter, Input, OnChanges, OnInit, Output, ViewChild} from '@angular/core';
import {AppCategory} from '../../../models/AppCategory';
import {AppTreeNode} from './dataModel';
import {AppNodeType, AppTreeNode} from './dataModel';
import {mapToTreeNodes} from './dataMapper';
import {ITreeNode} from 'angular-tree-component/dist/defs/api';
import {AppQuestion} from "../../../models/AppQuestion";
Expand Down Expand Up @@ -59,34 +59,20 @@ export class QuestionTreeComponent implements OnChanges {
return null;
}

sourceMap;
public syncWithForm() {
this.treeNodes = mapToTreeNodes(this.rootCategory);
let {nodes, sourceMap} = mapToTreeNodes(this.rootCategory);
this.treeNodes = nodes;
this.sourceMap = sourceMap;
}

public lookupInForm(nodeID: number): AppQuestion | AppCategory {
// BFS
let start = this.rootCategory;
let queue: AppCategory[] = [start];
while(queue.length > 0){
let current = queue.pop();
if(current.id == nodeID) return current;
for(let i = 0; i < current.questions.length; i++)
if(nodeID === current.questions[i].id)
return current.questions[i];
queue.push(...current.children);
}
return null;
}


/**
* ===========================================================
* INPUT OPTIONS
* ( Use these input properties to configure behavior )
* ===========================================================
*/
@Input() allowDrop = (node, parent) => false;
@Input() allowDrag = false;
@Input() allowDrag = true;


/**
Expand All @@ -109,7 +95,7 @@ export class QuestionTreeComponent implements OnChanges {
}
},
allowDrop: (node, { parent, index }) => {
return this.allowDrop(node.data, parent.data);
return parent.data.type === AppNodeType.category;
}
};

Expand Down
13 changes: 8 additions & 5 deletions src/app/shared/responses/converters.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import {AppResponse} from "../../models/AppResponse";
import {RESPONSE_FORMATS as fmt} from "../../models/formats";

export function renderToString(response: AppResponse){
if(!response) return '';
if(typeof response === 'string')
return response;
switch (response.type){
case "txt":
case fmt.TEXT:
return response.txt;
case "sel":
case fmt.SELECT:
return response.sel;
case "boo":
case fmt.BOOLEAN:
return response.boo;
case "num":
case fmt.NUMBER:
return response.num;
case "multi-sel":
case fmt.MULTI_SELECT:
return response.selections.map(sel => sel.txt).join(', ');
case fmt.NOT_REPORTED:
return 'NOT_REPORTED';
}
}

0 comments on commit 90d29f6

Please sign in to comment.