Skip to content

Commit

Permalink
Merge pull request #1494 from ever-co/feat/#806-adding-OKR-module
Browse files Browse the repository at this point in the history
Feat/#806 adding okr module
  • Loading branch information
rmagon committed Jun 23, 2020
2 parents 409a00e + 0281da6 commit 25c39d3
Show file tree
Hide file tree
Showing 26 changed files with 369 additions and 120 deletions.
33 changes: 32 additions & 1 deletion apps/api/src/app/goal-time-frame/goal-time-frame.controller.ts
Expand Up @@ -7,7 +7,8 @@ import {
Get,
HttpCode,
Delete,
Param
Param,
Put
} from '@nestjs/common';
import { CrudController } from '../core';
import { GoalTimeFrame } from './goal-time-frame.entity';
Expand Down Expand Up @@ -67,4 +68,34 @@ export class GoalTimeFrameController extends CrudController<GoalTimeFrame> {
async deleteTask(@Param('id') id: string): Promise<any> {
return this.goalTimeFrameService.delete(id);
}
@ApiOperation({ summary: 'Update an existing record' })
@ApiResponse({
status: HttpStatus.CREATED,
description: 'The record has been successfully edited.'
})
@ApiResponse({
status: HttpStatus.NOT_FOUND,
description: 'Record not found'
})
@ApiResponse({
status: HttpStatus.BAD_REQUEST,
description:
'Invalid input, The response body may contain clues as to what went wrong'
})
@HttpCode(HttpStatus.ACCEPTED)
@Put(':id')
async update(
@Param('id') id: string,
@Body() entity: GoalTimeFrame
): Promise<GoalTimeFrame> {
try {
return this.goalTimeFrameService.create({
id,
...entity
});
} catch (error) {
console.log(error);
return;
}
}
}
9 changes: 8 additions & 1 deletion apps/api/src/app/goal/goal.controller.ts
Expand Up @@ -7,7 +7,8 @@ import {
HttpCode,
Put,
Param,
UseGuards
UseGuards,
Delete
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { GoalService } from './goal.service';
Expand Down Expand Up @@ -75,4 +76,10 @@ export class GoalController extends CrudController<Goal> {
return;
}
}

@HttpCode(HttpStatus.ACCEPTED)
@Delete(':id')
async deleteGoal(@Param('id') id: string): Promise<any> {
return this.goalService.delete(id);
}
}
4 changes: 3 additions & 1 deletion apps/api/src/app/keyresult/keyresult.entity.ts
Expand Up @@ -75,7 +75,9 @@ export class KeyResult extends Base implements IKeyResult {
status?: string;

@ApiProperty({ type: Goal })
@ManyToOne((type) => Goal, (goal) => goal.keyResults)
@ManyToOne((type) => Goal, (goal) => goal.keyResults, {
onDelete: 'CASCADE'
})
@JoinColumn({ name: 'goalId' })
goal: Goal;

Expand Down
7 changes: 7 additions & 0 deletions apps/gauzy/src/app/@core/services/goal-settings.service.ts
Expand Up @@ -57,4 +57,11 @@ export class GoalSettingsService {
this.toastrService.danger(error.message, 'Error');
return throwError(error.message);
}

update(id: string, goalTimeFrame: GoalTimeFrame): Promise<GoalTimeFrame> {
return this._http
.put<GoalTimeFrame>(`${this.TIME_FRAME_URL}/${id}`, goalTimeFrame)
.pipe(first())
.toPromise();
}
}
7 changes: 7 additions & 0 deletions apps/gauzy/src/app/@core/services/goal.service.ts
Expand Up @@ -46,6 +46,13 @@ export class GoalService {
.toPromise();
}

delete(id: string): Promise<any> {
return this._http
.delete(`${this.API_URL}/${id}`)
.pipe(first())
.toPromise();
}

errorHandler(error: HttpErrorResponse) {
this.toastrService.danger(error.message, 'Error');
return throwError(error.message);
Expand Down
10 changes: 5 additions & 5 deletions apps/gauzy/src/app/@core/services/keyresult.service.ts
Expand Up @@ -52,15 +52,15 @@ export class KeyResultService {
.pipe(catchError((error) => this.errorHandler(error)));
}

errorHandler(error: HttpErrorResponse) {
this.toastrService.danger(error.message, 'Error');
return throwError(error.message);
}

delete(id: string): Promise<any> {
return this._http
.delete(`${this.API_URL}/${id}`)
.pipe(first())
.toPromise();
}

errorHandler(error: HttpErrorResponse) {
this.toastrService.danger(error.message, 'Error');
return throwError(error.message);
}
}
Expand Up @@ -85,15 +85,15 @@
</nb-card-body>
<nb-card-footer>
<button class="mr-3" nbButton (click)="closeDialog(null)">
Cancel
{{ 'BUTTONS.CANCEL' | translate }}
</button>
<button
[disabled]="!timeFrameForm.valid"
nbButton
status="success"
(click)="saveTimeFrame()"
>
Save
{{ 'BUTTONS.SAVE' | translate }}
</button>
</nb-card-footer>
</nb-card>
Expand Up @@ -12,6 +12,8 @@ import { GoalTimeFrame } from '@gauzy/models';
export class EditTimeFrameComponent implements OnInit {
timeFrameForm: FormGroup;
timeFrame: GoalTimeFrame;
today = new Date();
type: string;
constructor(
private dialogRef: NbDialogRef<EditTimeFrameComponent>,
private fb: FormBuilder,
Expand All @@ -36,13 +38,23 @@ export class EditTimeFrameComponent implements OnInit {
}

async saveTimeFrame() {
await this.goalSettingsService
.createTimeFrame(this.timeFrameForm.value)
.then((res) => {
if (res) {
this.closeDialog(res);
}
});
if (this.type === 'add') {
await this.goalSettingsService
.createTimeFrame(this.timeFrameForm.value)
.then((res) => {
if (res) {
this.closeDialog(res);
}
});
} else {
await this.goalSettingsService
.update(this.timeFrame.id, this.timeFrameForm.value)
.then((res) => {
if (res) {
this.closeDialog(res);
}
});
}
}

closeDialog(val) {
Expand Down
Expand Up @@ -90,7 +90,8 @@ export class GoalSettingsComponent extends TranslationBaseComponent
}
const dialog = this.dialogService.open(EditTimeFrameComponent, {
context: {
timeFrame: this.selectedTimeFrame
timeFrame: this.selectedTimeFrame,
type: source
}
});

Expand Down
Expand Up @@ -122,6 +122,7 @@
Deadline
</label>
<nb-select
(selectedChange)="deadlineValidators()"
id="key-result-deadline"
fullWidth
formControlName="deadline"
Expand Down Expand Up @@ -155,6 +156,7 @@
/>
<nb-datepicker
#softDeadlinePicker
[min]="minDate"
[max]="
keyResultsForm.value.hardDeadline
? keyResultsForm.value.hardDeadline
Expand Down Expand Up @@ -186,22 +188,24 @@
[min]="
keyResultsForm.value.softDeadline
? keyResultsForm.value.softDeadline
: null
: minDate
"
></nb-datepicker>
</div>
</div>
</form>
</nb-card-body>
<nb-card-footer>
<button class="mr-3" nbButton (click)="closeDialog()">Cancel</button>
<button class="mr-3" nbButton (click)="closeDialog()">
{{ 'BUTTONS.CANCEL' | translate }}
</button>
<button
[disabled]="!keyResultsForm.valid"
[disabled]="keyResultsForm.invalid"
nbButton
status="success"
(click)="saveKeyResult()"
>
Save
{{ 'BUTTONS.SAVE' | translate }}
</button>
</nb-card-footer>
</nb-card>
Expand Up @@ -22,6 +22,7 @@ export class EditKeyResultsComponent implements OnInit, OnDestroy {
data: KeyResult;
showAllEmployees = false;
softDeadline: FormControl;
minDate = new Date();
private _ngDestroy$ = new Subject<void>();
constructor(
private dialogRef: NbDialogRef<EditKeyResultsComponent>,
Expand All @@ -30,10 +31,13 @@ export class EditKeyResultsComponent implements OnInit, OnDestroy {
) {}

ngOnInit() {
this.minDate = new Date(
this.minDate.setDate(this.minDate.getDate() + 1)
);
this.keyResultsForm = this.fb.group({
name: ['', Validators.required],
description: [''],
type: ['', Validators.required],
type: ['Number', Validators.required],
targetValue: [1],
initialValue: [0],
owner: ['', Validators.required],
Expand All @@ -52,12 +56,63 @@ export class EditKeyResultsComponent implements OnInit, OnDestroy {
if (!!this.data) {
this.keyResultsForm.patchValue(this.data);
this.keyResultsForm.patchValue({
softDeadline: new Date(this.data.softDeadline),
hardDeadline: new Date(this.data.hardDeadline)
softDeadline: this.data.softDeadline
? new Date(this.data.softDeadline)
: null,
hardDeadline: this.data.hardDeadline
? new Date(this.data.hardDeadline)
: null
});
}
}

deadlineValidators() {
if (
this.keyResultsForm.get('deadline').value === 'No Custom Deadline'
) {
this.keyResultsForm.controls['softDeadline'].clearValidators();
this.keyResultsForm.patchValue({ softDeadline: undefined });
this.keyResultsForm.controls[
'softDeadline'
].updateValueAndValidity();
this.keyResultsForm.controls['hardDeadline'].clearValidators();
this.keyResultsForm.patchValue({ hardDeadline: undefined });
this.keyResultsForm.controls[
'hardDeadline'
].updateValueAndValidity();
} else if (
this.keyResultsForm.get('deadline').value === 'Hard deadline'
) {
this.keyResultsForm.controls['softDeadline'].clearValidators();
this.keyResultsForm.patchValue({ softDeadline: undefined });
this.keyResultsForm.controls[
'softDeadline'
].updateValueAndValidity();
this.keyResultsForm.controls['hardDeadline'].setValidators([
Validators.required
]);
this.keyResultsForm.controls[
'hardDeadline'
].updateValueAndValidity();
} else if (
this.keyResultsForm.get('deadline').value ===
'Hard and soft deadline'
) {
this.keyResultsForm.controls['softDeadline'].setValidators([
Validators.required
]);
this.keyResultsForm.controls[
'softDeadline'
].updateValueAndValidity();
this.keyResultsForm.controls['hardDeadline'].setValidators([
Validators.required
]);
this.keyResultsForm.controls[
'hardDeadline'
].updateValueAndValidity();
}
}

selectEmployee(event, control) {
if (control === 'lead') {
this.keyResultsForm.patchValue({ lead: event });
Expand Down
@@ -1,4 +1,4 @@
<nb-card size="large">
<nb-card size="large" class="max-width-800">
<nb-card-header>
Add Objective
<nb-icon
Expand Down Expand Up @@ -41,9 +41,9 @@
fullWidth
selected="Organization"
>
<nb-option value="organization">Organization</nb-option>
<nb-option value="team">Team</nb-option>
<nb-option value="individual">Individual</nb-option>
<nb-option value="Organization">Organization</nb-option>
<nb-option value="Team">Team</nb-option>
<nb-option value="Individual">Individual</nb-option>
</nb-select>

<label for="objective-owner" class="label mt-3"> Owner </label>
Expand Down Expand Up @@ -74,6 +74,7 @@
Deadline
</label>
<nb-select
*ngIf="timeFrames.length > 0"
id="objective-deadline"
formControlName="deadline"
placeholder="Deadline"
Expand All @@ -86,17 +87,30 @@
>{{ deadline.name }}</nb-option
>
</nb-select>
<p>
<button
id="objective-deadline"
*ngIf="timeFrames.length == 0"
status="primary"
nbButton
(click)="openSetTimeFrame()"
>
Add Time Frame
</button>
</p>
</form>
</nb-card-body>
<nb-card-footer>
<button class="mr-3" nbButton (click)="closeDialog()">Cancel</button>
<button class="mr-3" nbButton (click)="closeDialog()">
{{ 'BUTTONS.CANCEL' | translate }}
</button>
<button
nbButton
[disabled]="!objectiveForm.valid"
status="success"
(click)="saveObjective()"
>
Save
{{ 'BUTTONS.SAVE' | translate }}
</button>
</nb-card-footer>
</nb-card>
@@ -0,0 +1,3 @@
.max-width-800 {
max-width: 800px;
}

0 comments on commit 25c39d3

Please sign in to comment.