This commit is contained in:
Manuel Romero
2021-11-26 11:08:45 +01:00
parent c3b8bd119f
commit 6283dddb22
7 changed files with 61 additions and 37 deletions

View File

@@ -9,5 +9,5 @@
<link rel="stylesheet" href="styles.921aafa95031aeb74181.css"></head>
<body>
<app-root></app-root>
<script src="runtime.689ba4fd6cadb82c1ac2.js" defer></script><script src="polyfills-es5.feb8e3dfdd8e1cace860.js" nomodule defer></script><script src="polyfills.60117177d3b4f4827ace.js" defer></script><script src="scripts.73c34722d75b092f2620.js" defer></script><script src="main.679c68481f0efd1a1571.js" defer></script></body>
<script src="runtime.689ba4fd6cadb82c1ac2.js" defer></script><script src="polyfills-es5.feb8e3dfdd8e1cace860.js" nomodule defer></script><script src="polyfills.60117177d3b4f4827ace.js" defer></script><script src="scripts.73c34722d75b092f2620.js" defer></script><script src="main.eca58c33a1ad840ee769.js" defer></script></body>
</html>

File diff suppressed because one or more lines are too long

View File

@@ -862,7 +862,7 @@ router.post('/:userId/provisions/:id/destroy', passport.ensureAuthenticatedAndIs
* description: Not found
*
*/
router.put('/:userId/provisions/:id/share/:withUserId', passport.ensureAuthenticated, async (req, res, next) => {
router.put('/:userId/provisions/:id/share/:withUserId', passport.ensureAuthenticatedAndIsMe, async (req, res, next) => {
try {
const userId = req.params.userId === 'me'? req.user._id : req.params.userId;

View File

@@ -4,27 +4,40 @@
<button type="button" class="close pull-right" aria-label="Close" (click)="modalRef.hide()">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title w-100 font-weight-bold">Share Provision</h4>
<h4 class="modal-title w-100 font-weight-bold">Share provision with others</h4>
</div>
<div>
Provision shared already with:
<div *ngFor="let withUser of sharedUsers; let i = index">{{withUser.displayName}}</div>
</div>
<div class="modal-body" style="max-height: 650px; overflow: auto;">
<div class="modal-body" style="max-height: 650px; overflow: auto;">
<div *ngIf="sharedUsers && sharedUsers.length > 0">
<label>Sharing this provision with: </label>
<table>
<tr *ngFor="let withUser of sharedUsers; let i = index">
<td>{{withUser.displayName}}</td>
<td>
<button style="margin-left: 10px;" class="lui-button lui-text-danger" (click)="stopShare(withUser._id);">
<span class="lui-icon lui-icon--bin" aria-hidden="true"></span>
</button>
</td>
</tr>
</table>
</div>
<div>
<section style="padding: 20px 0px;">
<label><mdb-icon fas icon="user"></mdb-icon> Share with (*):</label>
<select class="browser-default custom-select custom-select-sm" [(ngModel)]="selectedUser">
<label><mdb-icon fas icon="user"></mdb-icon> Share with:</label>
<select style="width: 250px;" class="browser-default custom-select custom-select-sm" [(ngModel)]="selectedUser">
<option *ngFor="let item of users" [value]="item._id">{{item.displayName}}</option>
</select>
</select>
<button class="lui-button text-success" (click)="share();">
Share
</button>
</section>
</div>
</div>
<div class="modal-footer d-flex justify-content-center">
<button style="margin-right: 100px;" *ngIf="sendData._id" mdbBtn color="danger" outline="true" class="waves-light" size="sm" mdbWavesEffect (click)="delete();">Delete</button>
<button mdbBtn color="dark-green" size="sm" outline="true" class="waves-effect" mdbWavesEffect (click)="modalRef.hide()">Cancel</button>
<button mdbBtn color="dark-green" class="waves-light" size="sm" mdbWavesEffect (click)="confirm();">Save</button>
<button mdbBtn color="dark-green" size="sm" outline="true" class="waves-effect" mdbWavesEffect (click)="modalRef.hide()">Close</button>
</div>
</div>
<!--/.Content-->

View File

@@ -16,46 +16,49 @@ export class ShareModalComponent implements OnInit, OnDestroy {
action: Subject<any> = new Subject();
users;
sharedUsers;
currentUser;
selectedUser;
sendData : any = {};
constructor( private _auth: AuthGuard, public modalRef: MDBModalRef, private _usersService: UsersService, private _provisionsService: ProvisionsService ) {
}
refresh() : void {
this._provisionsService.getSharesForProvision(this.provision.user._id, this.provision._id).subscribe(res=> {
this.sharedUsers = res;
});
}
ngOnInit() {
this._usersService.getUsers(true).subscribe(res=> {
this.users = res.results;
if ( this.provision.user ) {
this.selectedUser = this.provision.user._id;
}
this.users = res.results;
});
this._provisionsService.getSharesForProvision(this.provision.user._id, this.provision._id).subscribe(res=> {
this.sharedUsers = res;
});
this.refresh();
}
ngOnDestroy() {
}
confirm() : void {
this.sendData.user = this.selectedUser;
share() : void {
console.log("SendData", this.sendData);
//this.modalRef.hide();
/*this._provisionsService.updateProvisionUser(this.provision._id, this.provision.user._id, this.sendData ).subscribe( res=>{
let user = this.users.filter( u => u._id === this.selectedUser);
this.action.next({"user": user[0]});
this.modalRef.hide();
});*/
this._provisionsService.shareProvision(this.provision.user._id, this.provision._id, this.selectedUser ).subscribe( res=>{
this.refresh();
//this.modalRef.hide();
});
}
stopShare(withUserId) : void {
//this.modalRef.hide();
this._provisionsService.stopShareProvision(this.provision.user._id, this.provision._id, withUserId ).subscribe( res=>{
this.refresh();
//this.modalRef.hide();
});
}
}

View File

@@ -101,7 +101,7 @@
</div>
</div>
<div *ngIf="!provisions || provisions.length === 0" style="text-align: center;">
<p>You don't have any shared provisions.</p>
<p>No one has shared any provisions with you yet.</p>
</div>
</div>

View File

@@ -71,6 +71,14 @@ export class ProvisionsService {
}));
}
shareProvision(userId, provisionId, withUserId): Observable<any> {
return this.httpClient.put(`${environment.apiVersionPath}/users/${userId}/provisions/${provisionId}/share/${withUserId}`, null);
}
stopShareProvision(userId, provisionId, withUserId): Observable<any> {
return this.httpClient.delete(`${environment.apiVersionPath}/users/${userId}/provisions/${provisionId}/share/${withUserId}`);
}
getProvisionById(id) : Observable<any> {
return this.httpClient.get(`${environment.apiVersionPath}/provisions/${id}`).pipe(map((p:any)=>{
this.timeRunning(p);