Projekt

Obecné

Profil

« Předchozí | Další » 

Revize ea0e5344

Přidáno uživatelem Jakub Hlaváč před více než 3 roky(ů)

Re #8788 - Odstranění unit - endpoint

+ OpenAPI definition for deleting unit
+ adding button to delete unit
+ adding confirm dialog if deleting unit

Zobrazit rozdíly:

src/app/app.module.ts
13 13
import {SensorModule} from './sensor/sensor.module';
14 14
import {FontAwesomeModule} from '@fortawesome/angular-fontawesome';
15 15
import {UnitModule} from './unit/unit.module';
16
import {ConfirmationService, MessageService} from 'primeng/api';
16 17

  
17 18
@NgModule({
18 19
  declarations: [
......
30 31
    AdministrationModule,
31 32
    SensorModule,
32 33
    FontAwesomeModule,
33
    UnitModule
34
    UnitModule,
35
  ],
36
  providers: [
37
    ConfirmationService,
38
    MessageService,
34 39
  ],
35
  providers: [],
36 40
  bootstrap: [AppComponent]
37 41
})
38 42
export class AppModule {
src/app/dashboard/components/dashboard.component.html
11 11
    <p-accordionTab *ngFor="let unit of units">
12 12
      <p-header [className]="'dashboard-unit-wrapper'">
13 13
        <div [className]="'row dashboard-unit'">
14
          <div class="col-md-6">{{ unit.unit.description}}</div>
15
          <div class="col-md-6 text-right">
14
          <div class="col-md-5">{{ unit.unit.description}}</div>
15
          <div class="col-md-7 text-right">
16 16
            <p-button label="Sensors graph" icon="pi pi-chart-line" [routerLink]="['/dashboard/unit', unit.unit.unitId]"></p-button>
17 17
            <p-button label="Add sensor" icon="pi pi-cog" (onClick)="addSensor($event, unit.unit)"></p-button>
18 18
            <p-button label="Edit unit" icon="pi pi-cog" (onClick)="editUnit($event, unit.unit)"></p-button>
19
            <p-button label="Delete unit" icon="pi pi-cog" (onClick)="deleteUnit($event, unit.unit)"></p-button>
19 20
          </div>
20 21
        </div>
21 22
      </p-header>
......
29 30
<app-unit-popup *ngIf="editedUnit" [(isVisible)]="showEditUnitPopup" [unit]="editedUnit"></app-unit-popup>
30 31
<app-unit-insert-popup [(isVisible)]="showInsertUnitPopup" [phenomenons]="phenomenons"></app-unit-insert-popup>
31 32
<app-sensor-insert-popup *ngIf="editedUnit" [unit]="editedUnit" [(isVisible)]="showInsertSensorPopup" [phenomenons]="phenomenons"></app-sensor-insert-popup>
33

  
34

  
35

  
36
<p-confirmDialog [style]="{width: '50vw'}" key="positionDialog" [position]="position" [baseZIndex]="10000" rejectButtonStyleClass="p-button-outlined"></p-confirmDialog>
src/app/dashboard/components/dashboard.component.ts
7 7
import {Unit} from '../../shared/api/endpoints/models/unit';
8 8
import {DataService} from '../../shared/api/endpoints/services/data.service';
9 9
import {tap} from 'rxjs/operators';
10
import {Observable} from 'rxjs';
11 10
import {Phenomenon} from '../../shared/api/endpoints/models/phenomenon';
12 11
import {SensorsService} from '../../shared/api/endpoints/services/sensors.service';
12
import {ConfirmationService, ConfirmEventType, MessageService} from 'primeng/api';
13
import {ManagementService} from '../../shared/api/endpoints/services/management.service';
14
import {InsertUnit} from '../../shared/api/endpoints/models/insert-unit';
13 15

  
14 16
@Component({
15 17
  selector: 'app-dashboard',
......
18 20
})
19 21
export class DashboardComponent implements OnInit {
20 22

  
23
  position: 'bottom';
21 24
  groups: Group[];
22 25
  units: Array<{ drivers?: Drivers; generalInfo?: GeneralInfo; holder?: any; lastpos?: Lastpos; sensors?: Array<Sensor>; unit?: Unit }>;
23 26
  showInsertUnitPopup = false;
......
28 31

  
29 32
  constructor(
30 33
    private dataService: DataService,
31
    private sensorService: SensorsService
34
    private sensorService: SensorsService,
35
    private confirmationService: ConfirmationService,
36
    private messageService: MessageService,
37
    private managementService: ManagementService
32 38
  ) {
33 39
    this.sensorService.getPhenomenons().subscribe(
34 40
      response => this.phenomenons = response
......
67 73
    this.showInsertSensorPopup = true;
68 74
    this.editedUnit = unit;
69 75
  }
76

  
77
  deleteUnit($event: any, unit: Unit) {
78
    $event.stopPropagation();
79
    this.confirmationService.confirm({
80
      message: 'Do you want to delete this unit?',
81
      header: 'Delete Unit Confirmation',
82
      icon: 'pi pi-info-circle',
83
      accept: () => {
84
        console.log('ACCEPTED');
85
        // this.processUnitDeletion(unit);
86
        // this.messageService.add({severity:'info', summary:'Confirmed', detail:'Record deleted'});
87
      },
88
      reject: () => {
89
        console.log('REJECTED');
90
      },
91
      key: 'positionDialog'
92
    });
93
  }
94

  
95
  processUnitDeletion(insertUnit: InsertUnit) {
96
    this.managementService.deleteUnit({body: {unit: insertUnit}});
97
  }
70 98
}
src/app/dashboard/dashboard.module.ts
12 12
import { UnitInsertPopupComponent } from './components/unit-insert-popup/unit-insert-popup.component';
13 13
import {ReactiveFormsModule} from '@angular/forms';
14 14
import { SensorInsertPopupComponent } from './components/sensor-insert-popup/sensor-insert-popup.component';
15
import {ConfirmDialogModule} from 'primeng/confirmdialog';
15 16

  
16 17

  
17 18

  
18 19
@NgModule({
19
  declarations: [DashboardComponent, SensorsComponent, UnitPopupComponent, SensorPopupComponent, UnitInsertPopupComponent, SensorInsertPopupComponent],
20
  declarations: [DashboardComponent, SensorsComponent, UnitPopupComponent, SensorPopupComponent, UnitInsertPopupComponent,
21
    SensorInsertPopupComponent],
20 22
  imports: [
21 23
    CommonModule,
22 24
    NavBarModule,
......
24 26
    ButtonModule,
25 27
    AccordionModule,
26 28
    DialogModule,
27
    ReactiveFormsModule
29
    ReactiveFormsModule,
30
    ConfirmDialogModule
28 31
  ]
29 32
})
30 33
export class DashboardModule { }
src/app/shared/api/endpoints/api.module.ts
41 41
    }
42 42
  }
43 43

  
44
  constructor(
44
  constructor( 
45 45
    @Optional() @SkipSelf() parentModule: ApiModule,
46 46
    @Optional() http: HttpClient
47 47
  ) {
src/app/shared/api/endpoints/services/management.service.ts
135 135
    );
136 136
  }
137 137

  
138
  /**
139
   * Path part for operation deleteUnit
140
   */
141
  static readonly DeleteUnitPath = '/senslog15/ManagementService?Operation=DeleteUnit';
142

  
143
  /**
144
   * Delete Unit.
145
   *
146
   *
147
   *
148
   * This method provides access to the full `HttpResponse`, allowing access to response headers.
149
   * To access only the response body, use `deleteUnit()` instead.
150
   *
151
   * This method sends `application/json` and handles request body of type `application/json`.
152
   */
153
  deleteUnit$Response(params: {
154
    body: { 'unit'?: InsertUnit }
155
  }): Observable<StrictHttpResponse<{ 'message'?: string }>> {
156

  
157
    const rb = new RequestBuilder(this.rootUrl, ManagementService.DeleteUnitPath, 'delete');
158
    if (params) {
159
      rb.body(params.body, 'application/json');
160
    }
161

  
162
    return this.http.request(rb.build({
163
      responseType: 'json',
164
      accept: 'application/json'
165
    })).pipe(
166
      filter((r: any) => r instanceof HttpResponse),
167
      map((r: HttpResponse<any>) => {
168
        return r as StrictHttpResponse<{ 'message'?: string }>;
169
      })
170
    );
171
  }
172

  
173
  /**
174
   * Delete Unit.
175
   *
176
   *
177
   *
178
   * This method provides access to only to the response body.
179
   * To access the full response (for headers, for example), `deleteUnit$Response()` instead.
180
   *
181
   * This method sends `application/json` and handles request body of type `application/json`.
182
   */
183
  deleteUnit(params: {
184
    body: { 'unit'?: InsertUnit }
185
  }): Observable<{ 'message'?: string }> {
186

  
187
    return this.deleteUnit$Response(params).pipe(
188
      map((r: StrictHttpResponse<{ 'message'?: string }>) => r.body as { 'message'?: string })
189
    );
190
  }
191

  
138 192
}
src/app/shared/api/openapi.yaml
228 228
                unit:
229 229
                  $ref: '#/components/schemas/InsertUnit'
230 230

  
231
  /senslog15/ManagementService?Operation=DeleteUnit:
232
    delete:
233
      tags:
234
        - management
235
      summary: Delete Unit
236
      operationId: deleteUnit
237
      responses:
238
        200:
239
          description: deleted
240
          content:
241
            application/json:
242
              schema:
243
                type: object
244
                properties:
245
                  message:
246
                    type: string
247
      requestBody:
248
        required: true
249
        content:
250
          application/json:
251
            schema:
252
              type: object
253
              properties:
254
                unit:
255
                  $ref: '#/components/schemas/InsertUnit'
256

  
231 257

  
232 258
components:
233 259
  schemas:

Také k dispozici: Unified diff