Skip to content

Commit

Permalink
Merge pull request #44 from PolyHx/task/add-questions-and-track-types
Browse files Browse the repository at this point in the history
Add questions and tracks types
  • Loading branch information
BrandonRbg authored Mar 20, 2019
2 parents 148a298 + 22306dc commit 4a06eca
Show file tree
Hide file tree
Showing 17 changed files with 320 additions and 88 deletions.
20 changes: 19 additions & 1 deletion src/app/api/models/puzzle-hero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,25 @@ export enum TrackTypes {
Crypto = "crypto",
Gaming = "gaming",
Scavenger = "scavenger",
Sponsor = "sponsor"
Sponsor = "sponsor",
Vine = "vine",
EsotericLanguages = "esoteric_languages",
DataAnalysis = "data_analysis",
Recon = "recon",
Steganography = "steganography",
Debugging = "debugging",
Forensics = "forensics",
Charades = "charades",
ReverseEngineering = "reverse_engineering",
CodeGolf = "code_golf",
Regex = "regex",
Scripting = "scripting",
Food = "food",
Karaoke = "karaoke",
Pwning = "pwning",
Authentication = "authentication",
StaticAnalysis = "static_analysis",
ArtificialIntelligence = "artificial_intelligence"
}

export interface PuzzleInfo {
Expand Down
20 changes: 19 additions & 1 deletion src/app/api/models/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,25 @@ export enum QuestionTypes {
Gaming = "gaming",
Scavenger = "scavenger",
Sponsor = "sponsor",
Upload = "upload"
Upload = "upload",
Vine = "vine",
EsotericLanguages = "esoteric_languages",
DataAnalysis = "data_analysis",
Recon = "recon",
Steganography = "steganography",
Debugging = "debugging",
Forensics = "forensics",
Charades = "charades",
ReverseEngineering = "reverse_engineering",
CodeGolf = "code_golf",
Regex = "regex",
Scripting = "scripting",
Food = "food",
Karaoke = "karaoke",
Pwning = "pwning",
Authentication = "authentication",
StaticAnalysis = "static_analysis",
ArtificialIntelligence = "artificial_intelligence"
}

export enum ValidationTypes {
Expand Down
15 changes: 3 additions & 12 deletions src/app/components/question-form/question-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { QUESTION_FORM_GENERATOR } from "./question-form.constants";
import { ControlValueAccessor, FormGroup, NG_VALUE_ACCESSOR } from "@angular/forms";
import { Subscription } from "rxjs";
import { InputTypes, QuestionTypes, ValidationTypes } from "../../api/models/question";
import { QuestionUtils } from "../../utils/question.utils";

@Component({
selector: "app-question-form",
Expand Down Expand Up @@ -79,18 +80,8 @@ export class QuestionFormComponent implements OnInit, ControlValueAccessor, OnDe
return false;
}

getQuestionTypeIcon(type: string): string {
switch (type) {
case QuestionTypes.Crypto:
return "fa-key";
case QuestionTypes.Gaming:
return "fa-gamepad";
case QuestionTypes.Scavenger:
return "fa-camera-alt";
case QuestionTypes.Sponsor:
return "fa-gem";
}
return "";
getQuestionTypeIcon(type: QuestionTypes): string {
return QuestionUtils.getQuestionTypeIconClass(type);
}

getValidationIcon(type: string): string {
Expand Down
10 changes: 5 additions & 5 deletions src/app/components/question-form/question-form.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
placeholder='{{ "components.question_form.puzzle_types" | translate }}' controlStatus
formControlName="type">
<ng-template ng-option-tmp ng-label-tmp let-item="item">
<i class="fal" [ngClass]="getQuestionTypeIcon(item)"></i>
<i [ngClass]="getQuestionTypeIcon(item)"></i>&nbsp;
<span class="ng-option-label">
{{ item }}
</span>
{{ "general.question.types." + item | translate }}
</span>
</ng-template>
</ng-select>
</div>
Expand All @@ -44,7 +44,7 @@
placeholder='{{ "components.question_form.validation_types" | translate }}' controlStatus
formControlName="validationType">
<ng-template ng-option-tmp ng-label-tmp let-item="item">
<i class="fal" [ngClass]="getValidationIcon(item)"></i>
<i class="fal" [ngClass]="getValidationIcon(item)"></i>&nbsp;
<span class="ng-option-label">
{{ item }}
</span>
Expand Down Expand Up @@ -73,7 +73,7 @@
placeholder='{{ "components.question_form.input_types" | translate }}' controlStatus
formControlName="inputType">
<ng-template ng-option-tmp ng-label-tmp let-item="item">
<i class="fal" [ngClass]="getInputTypeIcon(item)"></i>
<i class="fal" [ngClass]="getInputTypeIcon(item)"></i>&nbsp;
<span class="ng-option-label">
{{ item }}
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output } from "@angular/core";
import { InputTypes, Question, QuestionGraphNode, QuestionTypes, ValidationTypes } from "../../../../../api/models/question";
import { QuestionUtils } from "../../../../../utils/question.utils";

@Component({
selector: "app-question-edit-card",
Expand All @@ -25,17 +26,7 @@ export class QuestionEditCardComponent implements OnInit {
}

get icon(): string {
switch ((this.question.question as Question).type) {
case QuestionTypes.Crypto:
return "fal fa-key";
case QuestionTypes.Gaming:
return "fal fa-gamepad";
case QuestionTypes.Scavenger:
return "fal fa-camera-alt";
case QuestionTypes.Upload:
return "fal fa-upload";
}
return "";
return QuestionUtils.getQuestionTypeIconClass((this.question.question as Question).type);
}

get validationIcon(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
</div>
<div fxFlex>
<strong>
<i class="fal" [ngClass]="icon"></i>&nbsp;{{ question?.question?.type }}<br>
<i class="fal"
[ngClass]="icon"></i>&nbsp;{{ "general.question.types." + question?.question?.type | translate }}
<br>
<i class="fal" [ngClass]="inputIcon"></i>&nbsp;{{ question?.question?.inputType }}<br>
<i class="fal" [ngClass]="validationIcon"></i>&nbsp;{{ question?.question?.validationType }}
</strong>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core";
import { Question, QuestionTypes } from "../../../../../api/models/question";
import { QuestionUtils } from "../../../../../utils/question.utils";

@Component({
selector: "app-question-results-card",
Expand Down Expand Up @@ -28,17 +29,7 @@ export class QuestionResultsCardComponent implements OnInit {
}

get icon(): string {
switch (this.question.type) {
case QuestionTypes.Crypto:
return "fal fa-key";
case QuestionTypes.Gaming:
return "fal fa-gamepad";
case QuestionTypes.Scavenger:
return "fal fa-camera-alt";
case QuestionTypes.Upload:
return "fal fa-upload";
}
return "";
return QuestionUtils.getQuestionTypeIconClass(this.question.type);
}

onClickDownloadSubmissions(event: MouseEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { TrackFormDto } from "./dto/track-form.dto";
import { Subscription } from "rxjs";
import { ControlValueAccessor, FormGroup, NG_VALUE_ACCESSOR } from "@angular/forms";
import { TrackTypes } from "../../../../../api/models/puzzle-hero";
import { TrackUtils } from "../../../../../utils/track.utils";
import { QuestionTypes } from "../../../../../api/models/question";

@Component({
selector: "app-track-form",
Expand All @@ -20,12 +22,7 @@ import { TrackTypes } from "../../../../../api/models/puzzle-hero";
})
export class TrackFormComponent implements OnInit, ControlValueAccessor, OnDestroy {

public types = [
TrackTypes.Crypto,
TrackTypes.Gaming,
TrackTypes.Scavenger,
TrackTypes.Sponsor
];
public types = Object.values(TrackTypes);

public formGroup: FormGroup;

Expand Down Expand Up @@ -60,18 +57,8 @@ export class TrackFormComponent implements OnInit, ControlValueAccessor, OnDestr
}
}

getIcon(type: string): string {
switch (type) {
case TrackTypes.Crypto:
return "fa-key";
case TrackTypes.Gaming:
return "fa-gamepad";
case TrackTypes.Scavenger:
return "fa-camera-alt";
case TrackTypes.Sponsor:
return "fa-gem";
}
return "";
getIcon(type: TrackTypes): string {
return TrackUtils.getTrackTypeIconClass(type);
}

validate(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ng-select [items]="types" [clearable]="false" placeholder='{{ "components.track_form.type" | translate }}'
formControlName="type" controlStatus>
<ng-template ng-option-tmp ng-label-tmp let-item="item">
<i class="fal" [ngClass]="getIcon(item)"></i>
<i [ngClass]="getIcon(item)"></i>
<span class="ng-option-label">
{{ "general.track.types." + item | translate }}
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, EventEmitter, Input, Output, ViewChild } from "@angular/core
import { PuzzleInfo } from "../../../../api/models/puzzle-hero";
import { PopoverDirective } from "ngx-bootstrap";
import { QuestionTypes } from "../../../../api/models/question";
import { QuestionUtils } from "../../../../utils/question.utils";

@Component({
selector: "[puzzle-tile]",
Expand All @@ -25,17 +26,7 @@ export class PuzzleTileComponent {
clickAddPuzzle = new EventEmitter<void>();

get icon(): string {
switch (this.puzzle.type) {
case QuestionTypes.Crypto:
return "&#xf084;";
case QuestionTypes.Gaming:
return "&#xf11b;";
case QuestionTypes.Scavenger:
return "&#xf332;";
case QuestionTypes.Sponsor:
return "&#xf3a5;";
}
return "";
return QuestionUtils.getQuestionTypeIconCharacter(this.puzzle.type);
}

onClickPuzzle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
[class.completed]="puzzle?.completed"/>

<svg width="77" height="77">
<svg:text class="fal fa-3x" x="50%" y="50%" alignment-baseline="middle" dominant-baseline="middle"
<svg:text [ngClass]="{fal: puzzle.type !== 'vine', fab: puzzle.type === 'vine'}" class="fa-3x" x="50%"
y="50%" alignment-baseline="middle" dominant-baseline="middle"
text-anchor="middle" [innerHTML]="icon">
</svg:text>
<svg:text class="fa fa-3x text-danger" x="50%" y="50%" alignment-baseline="middle"
Expand Down
15 changes: 3 additions & 12 deletions src/app/features/puzzle-hero/components/track/track.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core";
import * as shape from "d3-shape";
import { PuzzleInfo, Track, TrackTypes } from "../../../../api/models/puzzle-hero";
import { PuzzleInfo, Track } from "../../../../api/models/puzzle-hero";
import { PuzzleHeroService } from "../../../../providers/puzzle-hero.service";
import { SimpleModalService } from "ngx-simple-modal";
import { TrackUtils } from "../../../../utils/track.utils";

@Component({
selector: "app-track",
Expand Down Expand Up @@ -71,17 +72,7 @@ export class TrackComponent implements OnInit {
}

get icon(): string {
switch (this.track.type) {
case TrackTypes.Crypto:
return "fa-key";
case TrackTypes.Gaming:
return "fa-gamepad";
case TrackTypes.Scavenger:
return "fa-camera-alt";
case TrackTypes.Sponsor:
return "fa-gem";
}
return "";
return TrackUtils.getTrackTypeIconClass(this.track.type);
}

get isStarred(): boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<accordion class="card-wrapper">
<accordion-group (isOpenChange)="onOpen()" [isOpen]="startsOpen">
<div accordion-heading fxLayout="row" fxLayoutAlign="start center">
<i class="fal firstIcon" [ngClass]="icon"></i>
<i class="firstIcon" [ngClass]="icon"></i>
<div class="track-title">
<span class="title">{{ track?.label }}</span><br>
<ng-container *ifRole="['admin', 'super-admin']">
Expand Down
Loading

0 comments on commit 4a06eca

Please sign in to comment.