Hima 6 년 전
부모
커밋
44b281e0c1

+ 3 - 0
src/app/dashboard/dashboard-routing.ts

@@ -76,6 +76,7 @@ import { RegistrationTraineeMovementAddComponent } from './Registration-trainee-
 import { PrintCardTraineeAddComponent } from './print-card-trainee/print-card-trainee-add/print-card-trainee-add.component';
 import { ModelVehicleListComponent } from './model-vehicle/model-vehicle-list/model-vehicle-list.component';
 import { ModelVehicleAddComponent } from './model-vehicle/model-vehicle-add/model-vehicle-add.component';
+import { RegistrationVehicleAddComponent } from './registration-vehicle/registration-vehicle-add/registration-vehicle-add.component';
 
 const dashboardRouting: Routes = [
     {path: 'service/:userID/:serviceID', component: ServiceItemComponent, canActivate: [AuthGuard], children: [
@@ -181,6 +182,8 @@ const dashboardRouting: Routes = [
     {path: 'vehicleModel/add' , component: ModelVehicleAddComponent},
     {path: 'vehicleModel/edit/:modelVehicleEditId', component:ModelVehicleAddComponent },
     {path: 'registrationVehicleList/:registrationVehicleListId', component: RegistrationVehicleListComponent},
+    {path: 'registrationVehicle/add', component: RegistrationVehicleAddComponent},
+    {path: 'registrationVehicle/edit/:registrationVehicleEditId', component:RegistrationVehicleAddComponent },
   ]},
 ];
 

+ 15 - 2
src/app/dashboard/model-vehicle/model-vehicle-add/model-vehicle-add.component.ts

@@ -14,7 +14,6 @@ import { NgForm } from '@angular/forms';
 })
 export class ModelVehicleAddComponent implements OnInit {
 
-  vehicle_types = [];
   constructor(private dashBoardSer: DashboardService, 
     private toastr: ToastrService, 
     private authSer: AuthServiceService, 
@@ -29,6 +28,7 @@ export class ModelVehicleAddComponent implements OnInit {
   typePage: string = '';
   checkSaveclick:boolean = false;
   vehicleId: number;
+  vehicle_types = [];
 
 
   formData = {
@@ -38,6 +38,19 @@ export class ModelVehicleAddComponent implements OnInit {
   }
 
   ngOnInit() {
+
+      //init the values of permision boolean
+      this.authSer.showAddBtn = false;
+      this.authSer.showDeleteBtn = false;
+      this.authSer.showEditBtn = false;
+      //show / hide notification search in header
+      this.authSer.notificationLogin = true;
+      this.authSer.showSearchHeader = false;
+      this.authSer.showHeaderLogin = false;
+      this.authSer.showHeaderDashBoard = true;
+      this.authSer.showDashboardHeader = true;
+      this.authSer.internalHeader = false;
+
      this.http.get(this.authSer.pathApi + '/get_vehicle_types_list').subscribe(
       (response) => {
         console.log(response);
@@ -107,8 +120,8 @@ export class ModelVehicleAddComponent implements OnInit {
           this.toastr.error('خطأ في الخادم ، حاول لاحقا !');
         }
       );
-
     }
+    
   }
 
 }

+ 88 - 3
src/app/dashboard/registration-vehicle/registration-vehicle-add/registration-vehicle-add.component.html

@@ -1,3 +1,88 @@
-<p>
-  registration-vehicle-add works!
-</p>
+<div class="addHospital-w">
+  <div class="container">
+    <div class="row" style="margin-bottom: 30px;">
+      <div class="col-12">
+        <ul class="list-unstyled titileLi-w">
+          <li class="headingText-w">خدمه الحركه  </li>
+          <li class="headingText-w" style="cursor:pointer" (click)="authSer.perviousLocation()">  تعريف أنواع المركبات</li>
+          <li class="headingText-w activeLi-w" style="margin-right:5px"> {{typePage}} </li>
+        </ul>
+      </div>
+    </div>
+    <div class="containerContent-w">
+
+    <div class="row">
+      <div class="col-12">
+
+        <form (ngSubmit)="onSubmitted()" #f="ngForm">
+          <div class="row">
+          
+            <div class="col-12 col-sm-12 col-md-4">
+              <div class="form-group">
+                <label for="vehicle_type_id" style="float: right; margin-right: 5px">نوع المركبه</label>
+                <select class="form-control" name="vehicle_type_id" [ngModel]="formData.vehicle_type_id" (input)="onChangeVehicleType($event)" required>
+                  <option *ngFor="let type of vehicle_types" [value]="type.id">{{type.name}}</option>
+                </select>
+              </div>
+            </div>
+
+            <div class="col-12 col-sm-12 col-md-4">
+              <div class="form-group">
+                <label for="vehicle_model_id" style="float: right; margin-right: 5px">إسم الموديل <span class="spanReqired-w">*</span></label>
+                <select class="form-control" name="vehicle_model_id" [ngModel]="formData.vehicle_model_id" required>
+                  <option *ngFor="let nameModel of modelNames" [value]="nameModel.id">{{nameModel.name}}</option>
+                </select>
+              </div>
+            </div>
+            
+            <div class="col-12 col-sm-12 col-md-4">
+              <div class="form-group">
+                <label for="sub_name" style="float: right; margin-right: 5px"> إسم الموديل الفرعي</label>
+                <input type="text" class="form-control" id="sub_name" name="sub_name" placeholder="الأسم" ngModel [ngModel]="formData.sub_name" #name="ngModel"/>
+              </div>
+            </div>
+
+            <div class="col-12 col-sm-12 col-md-4">
+              <div class="form-group">
+                <label style="float: right; margin-right: 5px">الحاله <span class="spanReqired-w">*</span></label>
+                <select class="form-control" name="vehicle_status" [ngModel]="formData.vehicle_status" required>
+                  <option value="new">جديد</option>
+                  <option value="used">مستعمل</option>
+                </select>
+              </div>
+            </div>
+
+            <div class="col-12 col-sm-12 col-md-4">
+              <div class="form-group">
+                <label id="plate_number" style="float: right; margin-right: 5px">رقم اللوحه <span class="spanReqired-w">*</span></label>
+                <input class="form-control" type="phone" placeholder="رقم اللوحه" name="plate_number" ngModel [ngModel]="formData.plate_number" required/>
+              </div>
+            </div>
+
+            <div class="col-12 col-sm-12 col-md-4">
+              <div class="form-group">
+                <label id="structure_number" style="float: right; margin-right: 5px">رقم الهيكل <span class="spanReqired-w">*</span></label>
+                <input class="form-control" type="phone" placeholder="رقم الهيكل" name="structure_number" ngModel [ngModel]="formData.structure_number" required/>
+              </div>
+            </div>
+
+            <div class="col-12 col-sm-12 col-md-4">
+              <div class="form-group">
+                <label id="structure_number" style="float: right; margin-right: 5px">اللون<span class="spanReqired-w">*</span></label>
+                <input class="form-control" type="text" placeholder="اللون" name="color" ngModel [ngModel]="formData.color" required/>
+              </div>
+            </div>
+
+            <div class="col-12">
+                <button type="submit" class="btn btn-success rightW" [disabled]="!f.valid || checkSaveclick">حفظ</button>
+                <button type="button" class="btn btn-warning rightW" (click)="authSer.backFromEdit()">إلغاء</button>
+            </div>
+
+          </div>
+        </form>
+
+      </div>
+    </div>
+  </div>
+  </div>
+</div>

+ 140 - 2
src/app/dashboard/registration-vehicle/registration-vehicle-add/registration-vehicle-add.component.ts

@@ -1,4 +1,12 @@
-import { Component, OnInit } from '@angular/core';
+import { HttpClient } from '@angular/common/http';
+import { NgxSpinnerService } from 'ngx-spinner';
+import { ActivatedRoute, Params } from '@angular/router';
+import { Location } from '@angular/common';
+import { AuthServiceService } from './../../../shared/auth-service.service';
+import { ToastrService } from 'ngx-toastr';
+import { DashboardService } from './../../../shared/dashboard.service';
+import { Component, OnInit, ViewChild } from '@angular/core';
+import { NgForm } from '@angular/forms';
 
 @Component({
   selector: 'app-registration-vehicle-add',
@@ -7,9 +15,139 @@ import { Component, OnInit } from '@angular/core';
 })
 export class RegistrationVehicleAddComponent implements OnInit {
 
-  constructor() { }
+  constructor(private dashBoardSer: DashboardService, 
+    private toastr: ToastrService, 
+    private authSer: AuthServiceService, 
+    private route: ActivatedRoute,
+    private spinner: NgxSpinnerService,
+    private location: Location,
+    private http: HttpClient
+  ) { }
+
+  @ViewChild('f') vehicleForm : NgForm;
+
+  typePage: string = '';
+  checkSaveclick:boolean = false;
+  vehicleId: number;
+  vehicle_types:any[] = [];
+  modelNames:any[] = [];
+  registerVehicleId: number;
+
+  formData = {
+    vehicle_status: '',
+    vehicle_type_id: '',
+    vehicle_model_id: '',
+    sub_name: '',
+    structure_number: '',
+    plate_number: '',
+    color: ''
+  }
 
   ngOnInit() {
+
+      //init the values of permision boolean
+      this.authSer.showAddBtn = false;
+      this.authSer.showDeleteBtn = false;
+      this.authSer.showEditBtn = false;
+      //show / hide notification search in header
+      this.authSer.notificationLogin = true;
+      this.authSer.showSearchHeader = false;
+      this.authSer.showHeaderLogin = false;
+      this.authSer.showHeaderDashBoard = true;
+      this.authSer.showDashboardHeader = true;
+      this.authSer.internalHeader = false;
+
+      this.http.get(this.authSer.pathApi + '/get_vehicle_types_list').subscribe(
+        (response) => {
+          console.log(response);
+          this.vehicle_types = response['types'];
+          
+        },
+        (error) => {
+          console.log(error);
+        });
+
+        this.route.params.subscribe(
+          (params: Params) => {
+            this.registerVehicleId = params['registrationVehicleEditId'];
+          }
+        );
+
+        if(this.registerVehicleId) {
+          this.spinner.show();
+          this.dashBoardSer.getItemData(this.registerVehicleId, 'registerVehicle').subscribe(
+            (responce) => {
+              console.log(responce);
+              this.formData.color = responce['data'].color;
+              this.formData.plate_number = responce['data'].plate_number;
+              this.formData.structure_number = responce['data'].structure_number;
+              this.formData.sub_name = responce['data'].sub_name ? responce['data'].sub_name : '';
+              this.formData.vehicle_model_id = responce['data'].vehicle_model_id;
+              this.formData.vehicle_status = responce['data'].vehicle_status;
+              this.formData.vehicle_type_id = responce['data'].vehicle_type_id;
+              this.getModelName(this.formData.vehicle_type_id);
+              this.spinner.hide();
+            },
+            (error) => {
+              console.log(error);
+            }
+          );
+        }
+       
+
+  }
+
+  onChangeVehicleType(event) {
+    const typeId = event.target.value;
+    this.getModelName(typeId);
+  }
+
+  getModelName(typeVehicleId) {
+    this.http.get(this.authSer.pathApi + '/get_vehicle_models_by_type_id/' + typeVehicleId).subscribe(
+      (responce) => {
+        console.log('types names of vehicles ', responce);
+        this.modelNames = responce['models'];
+        if(this.modelNames.length == 0) {
+          this.toastr.warning('لا يوجد اسماء موديل لهذا النوع');
+        }
+      },
+      (error) => {
+        console.log(error);
+      }
+    )
+  }
+
+
+  onSubmitted() {
+    this.checkSaveclick = true;
+    if(this.registerVehicleId) {
+      this.dashBoardSer.editItem(this.registerVehicleId, this.vehicleForm.value, 'registerVehicle').subscribe(
+        (responce) => {
+          console.log(responce);
+          this.toastr.success('تم التعديل بنجاح');
+          this.location.back();
+        },
+        (error) => {
+          console.log(error);
+          this.toastr.error('خطأ في الخادم ، رجاء المحارله لاحقا');
+        }
+      )
+    } else {
+      this.dashBoardSer.addItem(this.vehicleForm.value, 'registerVehicle').subscribe(
+        (responce) => {
+          console.log(responce);
+          this.toastr.success('تم الإضافه بنجاح');
+          this.checkSaveclick = false;
+          this.location.back();
+        },
+        (error) => {
+          console.log(error);
+          this.checkSaveclick = false;
+          this.toastr.error('خطأ في الخادم ، حاول لاحقا');
+        }
+      );
+    }
+    console.log(this.vehicleForm.value);
   }
 
 }

+ 9 - 9
src/app/dashboard/registration-vehicle/registration-vehicle-list/registration-vehicle-list.component.ts

@@ -235,13 +235,13 @@ export class RegistrationVehicleListComponent implements OnInit {
   };
 
   //add function
-  // onAdd() {
-  //   console.log('service/' + this.userLoginId + '/' + this.serviceId + '/addTab');
-  //   this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/vehicle/add']);
-  // }
-
-  // //edit function
-  //  onEdit(editTabID) {
-  //   this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/' + 'vehicle/edit/' + editTabID]);
-  // };
+  onAdd() {
+    console.log('service/' + this.userLoginId + '/' + this.serviceId + '/addTab');
+    this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/registrationVehicle/add']);
+  }
+
+  //edit function
+   onEdit(editTabID) {
+    this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/' + 'registrationVehicle/edit/' + editTabID]);
+  };
 }

+ 8 - 2
src/app/shared/dashboard.service.ts

@@ -90,8 +90,10 @@ export class DashboardService {
         return this.http.post(this.authService.pathApi + "/add_request", data);
       } else if(addType == 'vehicle') {
         return this.http.post(this.authService.pathApi + '/add_vehicle_type', data);
-      } else if('modelVehicle') {
+      } else if(addType == 'modelVehicle') {
         return this.http.post(this.authService.pathApi + '/add_vehicle_model', data);
+      } else if(addType == 'registerVehicle') {
+        return this.http.post(this.authService.pathApi + '/add_vehicle_data', data);
       }
     }
 
@@ -160,6 +162,8 @@ export class DashboardService {
         return this.http.post(this.authService.pathApi + '/edit_vehicle_type', editData);
       } else if(editPageName == 'vehicelModel') {
         return this.http.post(this.authService.pathApi + '/edit_vehicle_model', editData);
+      } else if(editPageName == 'registerVehicle') {
+        return this.http.post(this.authService.pathApi + '/edit_vehicle_data', editData);
       }
     }
 
@@ -206,8 +210,10 @@ export class DashboardService {
         return this.http.get(this.authService.pathApi + '/get_request/' + pageId);
       } else if(typeGetData == 'vehicle') {
         return this.http.get(this.authService.pathApi + '/get_vehicle_type/' + pageId);
-      } else if('vehicleModel') {
+      } else if(typeGetData == 'vehicleModel') {
         return this.http.get(this.authService.pathApi + '/get_vehicle_model/' + pageId);
+      } else if(typeGetData == 'registerVehicle') {
+        return this.http.get(this.authService.pathApi + '/get_vehicle_data/' + pageId);
       }
   }