Commit 96ebd933 authored by hasan khaddour's avatar hasan khaddour

fix projecgt modals

parent ba87b117
......@@ -88,5 +88,4 @@ export class AuthenticationService {
}
//#endregion Logout
}
import { Injectable } from '@angular/core';
import { DataStorageService } from '../dataStorage/data-storage.service';
import { User } from '../../models/users/User';
import { ROLES } from '../../constants/roles';
@Injectable({
providedIn: 'root'
......@@ -43,4 +44,13 @@ export class UserService {
.length !=0;
}
//#region authority
public isAuthorizedAsSeflOrDeputy( employeeId : number ){
return this.hasRole(ROLES.SCIENTIFIC_DEPUTY)|| this.getEmployeeId() == employeeId;
}
//#endregion authority
}
<!-- edit-participant-modal.component.html -->
<div class="modal fade" id="editParticipantModal" tabindex="-1" aria-labelledby="editParticipantModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="editParticipantModalLabel">تعديل معلومات مشاركة </h5>
<button type="button" class=" ml-4 mr-4 btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
<button type="button" class=" ml-4 mr-4 btn-close" (click)="closeModal()"></button>
</div>
<div class="modal-body">
<form [formGroup]="editParticipantForm" (ngSubmit)="onSubmit()">
......@@ -18,11 +14,8 @@
</div>
<button type="submit" class="col-4 offset-2 btn btn-primary" [disabled]="!editParticipantForm.valid">حفظ</button>
<button type="button" class="col-4 offset-2 btn btn-secondary" data-bs-dismiss="modal">إزالة</button>
<button type="button" (click)="closeModal()">إلغاء</button>
</form>
</div>
</div>
</div>
</div>
\ No newline at end of file
......@@ -19,7 +19,7 @@ export class EditParticipantModalComponent {
constructor(
private fb: FormBuilder,
private projectService: ProjectService,
private activeModal : NgbModal
private activeModal :NgbActiveModal
) {
this.editParticipantForm = this.fb.group({
role: ['', Validators.required],
......@@ -49,12 +49,13 @@ export class EditParticipantModalComponent {
.changeParticipation(request)
.subscribe(() => {
this.participantEdited.emit();
this.closeModal();
this.activeModal.close(request);
});
}
}
closeModal() {
this.activeModal.dismissAll();
this.activeModal.close();
}
}
......@@ -7,7 +7,7 @@
<button type="button" class="ml-4 mr-4 btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>هل أنت متأكد من أنك تريد إزالة السيد {{participant.employee.personalInfo | fullname}} من قائمة المشاركين في المشروع</p>
<p class="text-center text-danger">هل أنت متأكد من أنك تريد إزالة السيد {{participant.employee.personalInfo | fullname}} من قائمة المشاركين في المشروع</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">إلغاء</button>
......
......@@ -2,6 +2,7 @@ import { Component, EventEmitter, Input, Output } from '@angular/core';
import { EmployeeParticipate } from '../../../../employees/models/responses/employeeParticipate';
import { ProjectService } from '../../../services/project.service';
import { RemoveParticipantRequest } from '../../../models/requests/project-requests/RemoveParticipant';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'remove-participant-modal',
......@@ -12,7 +13,9 @@ export class RemoveParticipantModalComponent {
@Input() participant: EmployeeParticipate;
@Output() participantRemoved = new EventEmitter<void>();
constructor(private projectService: ProjectService) {}
constructor(private projectService: ProjectService,
private activeModal : NgbActiveModal
) {}
onConfirmRemove() {
let request :RemoveParticipantRequest= {
......@@ -23,7 +26,7 @@ export class RemoveParticipantModalComponent {
this.projectService
.removeParticipant(request)
.subscribe(() => {
this.participantRemoved.emit();
this.activeModal.close(this.participant.employeeId);
});
}
......
<p>remove-step-modal works!</p>
<div class="modal-header">
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
<h5 class="modal-title" id="modalLabel">حذف مرحلة </h5>
</div>
<div class="modal-body">
<p
class="text-center text-danger p-10"
>هل أنت متأكد من أنك تريد حذف المرحلة {{ step.stepInfo.stepName }}?</p>
<button type="button" class="btn m-4 btn-danger" (click)="onConfirmRemove()">حذف</button>
<button type="button" class="btn m-4 btn-secondary" (click)="onClose()">إلغاء</button>
</div>
......@@ -3,6 +3,7 @@ import { Step } from '../../../models/responses/Step';
import { ProjectService } from '../../../services/project.service';
import { StepService } from '../../../services/step.service';
import { ToastrService } from 'ngx-toastr';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'remove-step-modal',
......@@ -15,6 +16,7 @@ export class RemoveStepModalComponent {
constructor(
private stepService: StepService,
private activeModal :NgbActiveModal,
private toastr : ToastrService) {}
onConfirmRemove() {
......@@ -25,8 +27,8 @@ export class RemoveStepModalComponent {
.subscribe({
next: ()=>{
this.stepRemoved.emit();
this.activeModal.close(this.step.id);
},
error: (err)=>{
this
......@@ -39,4 +41,8 @@ export class RemoveStepModalComponent {
}
onClose(){
this.activeModal.close();
}
}
......@@ -36,10 +36,10 @@
<div class="col-auto">
<button type="button" [routerLink]="['/tracks/history/step/',step.id]" class="btn mr-2 btn-sm btn-primary">استعراض تاريخ متابعتها </button>
<button type="button"(click)="onChangeWeight()" class="btn mr-2 btn-sm btn-secondary">تعديل الثقل</button>
<button type="button" (click)="onEdit()" class="btn mr-2 btn-sm btn-secondary">تعديل المعلومات</button>
<button type="button" *ngIf="canSee" (click)="onChangeWeight()" class="btn mr-2 btn-sm btn-secondary">تعديل الثقل</button>
<button type="button" *ngIf="canSee" (click)="onEdit()" class="btn mr-2 btn-sm btn-secondary">تعديل المعلومات</button>
<button type="button" (click)="onDelete()" class="btn mr2 btn-sm btn-danger">إزالة</button>
<button type="button" *ngIf="canSee" (click)="onDelete()" class="btn mr2 btn-sm btn-danger">إزالة</button>
</div>
</div>
......
......@@ -9,6 +9,7 @@ import { Step } from '../../../models/responses/Step';
export class StepRowItemComponent {
@Input() step :Step
@Input() canSee :boolean
@Output() delete = new EventEmitter<void>();
@Output() edit = new EventEmitter<Step>();
@Output() changeWeight = new EventEmitter<Step>();
......
......@@ -3,10 +3,11 @@ import { Project } from '../../models/responses/project';
import { Employee } from '../../../employees/models/responses/employee';
import { ParticipationChange } from '../../models/responses/participationChange';
import { ProjectService } from '../../services/project.service';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { ToastrService } from 'ngx-toastr';
import { EmployeesService } from '../../../employees/services/employees.service';
import { EmployeeParticipate } from '../../../employees/models/responses/employeeParticipate';
import { UserService } from '../../../core/services/authentication/user.service';
@Component({
selector: 'participant-changes',
......@@ -25,6 +26,8 @@ export class ParticipantChangesComponent implements OnInit{
private projectService :ProjectService,
private employeeServie :EmployeesService,
private route :ActivatedRoute,
private userService : UserService,
private router :Router,
private toastr :ToastrService
){}
......@@ -35,7 +38,7 @@ export class ParticipantChangesComponent implements OnInit{
this
.participantId = Number(this.route.snapshot.paramMap.get('participantId'));
this
.employeeServie
.getEmployeeById(this.participantId)
......@@ -50,9 +53,24 @@ export class ParticipantChangesComponent implements OnInit{
.getProjectById(this.projectId)
.subscribe({
next:(data)=>{
this.project=data
this.currentParticipation=this.project.employeeParticipates.filter(e => e.employeeId == this.participantId)[0]
}
if(this.userService.isAuthorizedAsSeflOrDeputy(this.participantId)||data.projectManagerId == this.userService.getEmployeeId()){
this.project=data
this
.toastr
.success('لقد تم تحميل تاريخ التبدلات بنجاح');
this.currentParticipation=this.project.employeeParticipates.filter(e => e.employeeId == this.participantId)[0]
}else {
this.toastr.error('ليس لديك صلاحيات الولوج إلى هذه الصفحة')
this.router.navigate(['/forbiden'])
}
}
});
......@@ -64,10 +82,6 @@ export class ParticipantChangesComponent implements OnInit{
next: (data)=>{
this
.history=data.filter(e=> e.employeeId==this.participantId);
this
.toastr
.success('لقد تم تحميل تاريخ التبدلات بنجاح');
},
error:(err)=>{
......
......@@ -37,16 +37,13 @@
</div>
</div>
<edit-participant-modal
[participant]="selectedParticipant"
(participantEdited)="onParticipantUpdated()"
></edit-participant-modal>
<remove-participant-modal *ngIf="selectedParticipant"
<!-- <remove-participant-modal *ngIf="selectedParticipant"
[participant]="selectedParticipant"
(participantRemoved)="onParticipantRemoved()"
>
</remove-participant-modal>
> -->
<!--
</remove-participant-modal> -->
<!-- <app-remove-participant-modal [participant]="selectedParticipant" (participantRemoved)="onParticipantRemoved()"></app-remove-participant-modal> -->
......@@ -80,8 +77,8 @@
<div class="col-10">
<button type="button" class="btn m-2 btn-sm btn-primary">استعراض تاريخ تبدلاته </button>
<button type="button" data-bs-toggle="modal" data-bs-target="#editParticipantModal" class="btn m-2 btn-sm btn-secondary">تعديل معلومات المشاركة</button>
<button type="button" data-bs-toggle="modal" data-bs-target="#removeParticipantModal" class="btn m-2 btn-sm btn-danger">إزالة</button>
<button type="button" (click)="onParticipantUpdated()" class="btn m-2 btn-sm btn-secondary">تعديل معلومات المشاركة</button>
<button type="button" (click)="openDeleteModal()" class="btn m-2 btn-sm btn-danger">إزالة</button>
<button type="button" [routerLink]="['/reports/contributions',selectedParticipant.projectId,'employee',selectedParticipant.employeeId]" class="btn btn-sm btn-secondary">المساهمات</button>
</div>
......
......@@ -8,6 +8,9 @@ import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { AddParticipantModalComponent } from '../../components/modals/add-participant-modal/add-participant-modal.component';
import { ModalService } from '../../../core/services/modals/modal.service';
import { NgModel } from '@angular/forms';
import { RemoveParticipantModalComponent } from '../../components/modals/remove-participant-modal/remove-participant-modal.component';
import { EditParticipantModalComponent } from '../../components/modals/edit-participant-modal/edit-participant-modal.component';
import { ChangeEmployeeParticipationRequest } from '../../models/requests/project-requests/ChangeEmployeeParticipationRequest';
@Component({
selector: 'participants-list',
......@@ -26,7 +29,8 @@ export class ParticipantsListComponent {
private toastr : ToastrService,
private route: ActivatedRoute,
private activeModal : NgbModal,
public router :Router
public router :Router,
private modalService :NgbModal
) {
......@@ -48,7 +52,7 @@ export class ParticipantsListComponent {
}
onParticipantUpdated(): void {
this.activeModal.dismissAll();
this.loadParticipations();
}
......@@ -79,6 +83,49 @@ export class ParticipantsListComponent {
}
openDeleteModal(): void {
const modalRef = this.modalService.open(RemoveParticipantModalComponent);
modalRef.componentInstance.participant = this.selectedParticipant;
modalRef.result.then((result) => {
if (result) {
// Add the new project to the list
this.isDetailMode=false ;
this.participants=this.participants.filter(w => w.employeeId == this.selectedParticipant.employeeId)
}
}, (reason) => {
});
}
openUpdateModal(): void {
const modalRef = this.modalService.open(EditParticipantModalComponent);
modalRef.componentInstance.participant = this.selectedParticipant;
modalRef.result.then((result : ChangeEmployeeParticipationRequest) => {
if (result ) {
let part= this.participants.find(w => w.employeeId == this.selectedParticipant.employeeId)
part!.partialTimeRatio=result.partialTimeRation;
part!.role=result.role;
}
}, (reason) => {
});
}
onDetailMode(participant: EmployeeParticipate) {
this.selectedParticipant=participant ;
this.isDetailMode=true;
......
......@@ -6,7 +6,7 @@
<h2 class="h3 mb-0 page-title"> قائمة مراحل المشروع </h2>
</div>
<div class="col-auto">
<button type="button" (click)="openAddModal()" class="btn btn-primary"><span class="fe fe-file-plus fe-12 mr-2"></span>إضافة مرحلة </button>
<button type="button" *ngIf="canSee()" (click)="openAddModal()" class="btn btn-primary"><span class="fe fe-file-plus fe-12 mr-2"></span>إضافة مرحلة </button>
</div>
</div>
<hr>
......@@ -16,36 +16,22 @@
class=" offset-2"
*ngFor="let step of steps"
[step]="step"
(delete)="openModal('delete', step)"
[canSee]="canSee()"
(delete)="openDelteModal(step)"
(changeWeight)="openChangeWeightModal(step)"
(edit)="openEditModal(step)"
></step-row-item>
<div *ngIf="steps.length==0">
للأسف هذا المروع لايحوي على أية مراحل
</div>
</div>
</div>
</section>
<p class="tect-center">
<strong>
<div class="modal fade" id="stepModal" tabindex="-1" aria-labelledby="modalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
<h5 class="modal-title" id="modalLabel">{{ modalTitle }}</h5>
للأسف هذا المشروع لايحوي على أية مراحل
</div>
<div class="modal-body">
<!-- Delete Confirmation -->
<div *ngIf="modalMode === 'delete'">
<p>هل أنت متأكد من أنك تريد حذف المرحلة {{ selectedItem.stepInfo.stepName }}?</p>
<button type="button" class="btn m-4 btn-danger" (click)="delete()">حذف</button>
<button type="button" class="btn m-4 btn-secondary" (click)="closeModal()">إلغاء</button>
</div>
</div>
</div>
</strong>
</p>
</div>
</div>
</div>
\ No newline at end of file
</div>
</section>
......@@ -11,6 +11,7 @@ import { RemoveStepModalComponent } from '../../components/steps/remove-step-mod
import { EditStepModalComponent } from '../../components/step-modals/edit-step-modal/edit-step-modal.component';
import { EditWeightModalComponent } from '../../components/step-modals/edit-weight-modal/edit-weight-modal.component';
import { ChangeStepInfoRequest } from '../../models/requests/step-requests/changeStepInfoRequest';
import { Project } from '../../models/responses/project';
@Component({
selector: 'step-list',
templateUrl: './step-list.component.html',
......@@ -18,6 +19,7 @@ import { ChangeStepInfoRequest } from '../../models/requests/step-requests/chang
})
export class StepListComponent {
steps : Step[]
project : Project
modalMode: 'edit' | 'delete' = 'edit';
modalTitle: string = '';
selectedItem : Step;
......@@ -28,6 +30,7 @@ export class StepListComponent {
private toastr : ToastrService,
private route: ActivatedRoute,
public router :Router,
private projectService : ProjectService,
private modalService: NgbModal
) {
......@@ -40,9 +43,10 @@ export class StepListComponent {
loadParticipations(): void{
this.stepService.getStepsByProject(this.projectId).subscribe({
this.projectService.getProjectById(this.projectId).subscribe({
next: (data)=> {
this.steps= data
this.steps= data.steps
this.project=data;
this.toastr.success("تم تحميل المراحل بنجاح");
}
,
......@@ -88,6 +92,7 @@ export class StepListComponent {
});
}
openEditModal(step : Step): void {
const modalRef = this.modalService.open(EditStepModalComponent ,{size:'lg'});
......@@ -107,6 +112,26 @@ export class StepListComponent {
});
}
openDelteModal(step : Step): void {
const modalRef = this.modalService.open(RemoveStepModalComponent);
modalRef.componentInstance.step = step;
modalRef.result.then((result ) => {
if (result) {
// Add the new project to the list
this.delete(step.id)
}
}, (reason) => {
});
}
openModal(mode: 'edit' | 'delete', item: Step): void {
this.modalMode = mode;
this.selectedItem = { ...item }; // Clone project to prevent direct mutation
......@@ -123,29 +148,11 @@ export class StepListComponent {
}
}
delete(): void {
delete(id :number ): void {
this.stepService.deleteSep(this.selectedItem.id).subscribe({
next :()=>{
this.steps = this.steps.filter(p => p.id !== this.selectedItem.id);
this.steps = this.steps.filter(p => p.id !== id);
this.toastr.success("تم الحذف بنجاح")
this.closeModal();
}
,
error:(err)=>{
this.toastr.error("لقد حدث خطاء ما ")
this.closeModal();
}
}
);
}
......@@ -157,7 +164,7 @@ closeModal(): void {
}
canSee(){
return this.project.currentState.toLocaleLowerCase()=='inplan'
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment