Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Commit

Permalink
issue #647 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
BlakeDraper committed Jul 9, 2019
1 parent 0805873 commit dc41b57
Showing 1 changed file with 45 additions and 46 deletions.
91 changes: 45 additions & 46 deletions src/app/event-details/event-details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1207,31 +1207,33 @@ export class EventDetailsComponent implements OnInit {
}

removeCollaborator(userID, list) {
switch (list) {
case 'read':
const readIndex = this.readCollaboratorArray.findIndex(function (o) {
return o.id === userID;
});
if (readIndex !== -1) { this.readCollaboratorArray.splice(readIndex, 1); }
const readCollaboratorIDArray = [];
for (const user of this.readCollaboratorArray) {
readCollaboratorIDArray.push(user.id);
}
this.updateCollaboratorList('read', readCollaboratorIDArray);
break;
case 'write':
const writeIndex = this.writeCollaboratorArray.findIndex(function (o) {
return o.id === userID;
});
if (writeIndex !== -1) { this.writeCollaboratorArray.splice(writeIndex, 1); }
const writeCollaboratorIDArray = [];
for (const user of this.writeCollaboratorArray) {
writeCollaboratorIDArray.push(user.id);
}
this.updateCollaboratorList('write', writeCollaboratorIDArray);
break;

// WIP below. seems to be good. test a few more times.
if (list === 'read') {
const readIndex = this.readCollaboratorArray.findIndex(function (o) {
return o.id === userID;
});
if (readIndex !== -1) { this.readCollaboratorArray.splice(readIndex, 1); }
} else if (list === 'write') {
const writeIndex = this.writeCollaboratorArray.findIndex(function (o) {
return o.id === userID;
});
if (writeIndex !== -1) { this.writeCollaboratorArray.splice(writeIndex, 1); }

}

const readCollaboratorIDArray = [];
for (const user of this.readCollaboratorArray) {
readCollaboratorIDArray.push(user.id);
}

const writeCollaboratorIDArray = [];
for (const user of this.writeCollaboratorArray) {
writeCollaboratorIDArray.push(user.id);
}

this.updateCollaboratorList(readCollaboratorIDArray, writeCollaboratorIDArray);

}

addCollaborator(accessType) {
Expand All @@ -1249,26 +1251,22 @@ export class EventDetailsComponent implements OnInit {
if (selectedUser !== 'cancel') {

if (accessType === 'read') {

// move this to inside success
this.readCollaboratorArray.push(selectedUser);

const readCollaboratorIDArray = [];
for (const user of this.readCollaboratorArray) {
readCollaboratorIDArray.push(user.id);
}
this.updateCollaboratorList('read', readCollaboratorIDArray);

} else if (accessType === 'write') {

this.writeCollaboratorArray.push(selectedUser);
const writeCollaboratorIDArray = [];
for (const user of this.writeCollaboratorArray) {
writeCollaboratorIDArray.push(user.id);
}
this.updateCollaboratorList('write', writeCollaboratorIDArray);
}

const readCollaboratorIDArray = [];
for (const user of this.readCollaboratorArray) {
readCollaboratorIDArray.push(user.id);
}

const writeCollaboratorIDArray = [];
for (const user of this.writeCollaboratorArray) {
writeCollaboratorIDArray.push(user.id);
}

this.updateCollaboratorList(readCollaboratorIDArray, writeCollaboratorIDArray);
}

},
Expand Down Expand Up @@ -1314,16 +1312,17 @@ export class EventDetailsComponent implements OnInit {

}

updateCollaboratorList(accessType, userArray) {
updateCollaboratorList(readCollaboratorArray, writeCollaboratorArray) {

let update;
if (accessType === 'read') {
update = { 'id': this.eventData.id, 'new_read_collaborators': userArray };
} else if (accessType === 'write') {
update = { 'id': this.eventData.id, 'new_write_collaborators': userArray };
}
// tslint:disable-next-line:max-line-length
const update = { 'id': this.eventData.id, 'event_type': this.eventData.event_type, 'new_read_collaborators': readCollaboratorArray, 'new_write_collaborators': writeCollaboratorArray };
// if (accessType === 'read') {
// update = { 'id': this.eventData.id, 'event_type': this.eventData.event_type, 'new_read_collaborators': userArray };
// } else if (accessType === 'write') {
// update = { 'id': this.eventData.id, 'event_type': this.eventData.event_type, 'new_write_collaborators': userArray };
// }

this._eventService.patchUpdate(update)
this._eventService.update(update)
.subscribe(
(event) => {
// this.submitLoading = false;
Expand Down

0 comments on commit dc41b57

Please sign in to comment.