Skip to content

Commit

Permalink
duplication-error
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayj30pro committed Sep 20, 2024
1 parent 7546da4 commit b05c894
Showing 1 changed file with 3 additions and 129 deletions.
132 changes: 3 additions & 129 deletions src/app/pages/permissions-page/_services/permissions.model.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@ import { PermissionsApiService } from './permissions.api.service';
import { ModelTransformingService } from '@savvato-software/savvato-javascript-services';
import { UserRole } from '../_types/user-role.type';
import { User } from '../_types/user.type';
import { UserRole } from '../_types/user-role.type';
import { User } from '../_types/user.type';


@Injectable({
providedIn: 'root'
})
export class PermissionsModelService {

model: {} = {};
model: {} = {};

dirty = false;

allRoles = [];
allRoles = [];

selectedUserRoles = [];

newUserRoles = [];
newUserRoles = [];



Expand Down Expand Up @@ -54,156 +50,34 @@ export class PermissionsModelService {


}

dirtyOn() {
this.dirty = true;
}

dirtyOff() {
this.dirty = false;

}


getListOfUsers(): User[] {
console.log(this.model['listOfUsers']);
getListOfUsers() {
return this.model['listOfUsers'];
}


getListOfAllRoles(user) {
let availableRoles = this.model['listOfUserRoles'];
//console.log("raw form ",this.model['listOfUserRoles']);
this.allRoles = [];
if (availableRoles !== undefined && availableRoles !== null) {
this.allRoles = availableRoles.map(role => role['name']);
this.allRoles.sort();
this.getselectedUserRoles(user)
return this.allRoles;
}
}


getselectedUserRoles(currentUser) {
console.log("the user is ", currentUser);
if (currentUser !== '' && currentUser !== null) {
const selectedUser = this.model['listOfUsers'].find(user => user.name === currentUser);
this.selectedUserRoles = [];
for (let r in selectedUser.roles){
this.selectedUserRoles.push(selectedUser.roles[r].name);
}
this.selectedUserRoles.sort();

}
}

toggleRoles1(role: string){
let currentRoles = [];

if (this.newUserRoles.length == 0) {

currentRoles = this.selectedUserRoles;
}
else{
currentRoles = this.newUserRoles;
}

if (currentRoles.includes(role)) {
const remRole = currentRoles.indexOf(role)
currentRoles.splice(remRole,1);
}
else {
currentRoles.push(role);
}


this.newUserRoles = currentRoles;
this.newUserRoles.sort();

if (this.selectedUserRoles.toString() == this.newUserRoles.toString()) {
console.log('is not dirty');
this.dirtyOff();


}
else {
console.log('is dirty');
this.dirtyOn();
}

console.log("current state ", this.dirty);
console.log("selected ",this.selectedUserRoles);
console.log("new ",this.newUserRoles);

}

toggleRoles(role: string){

if (this.newUserRoles.length == 0) {
this.newUserRoles = this.selectedUserRoles.map(role => role);
}

if (this.newUserRoles.includes(role)) {
const remRole = this.newUserRoles.indexOf(role)
this.newUserRoles.splice(remRole,1);
}
else {
this.newUserRoles.push(role);
}

this.newUserRoles.sort();

if (this.selectedUserRoles.toString() == this.newUserRoles.toString()) {
console.log('is not dirty');
this.dirtyOff();
}

else {
console.log('is dirty');
this.dirtyOn();
}

}



getListOfRoles(): UserRole {
getListOfRoles() {
return this.model['listOfUserRoles'];
}

isDirty(): boolean {
return this.dirty;
isDirty(): boolean {
return this.dirty;
}

clearValues(){
this.selectedUserRoles = [];
clearValues(){
this.selectedUserRoles = [];
this.dirty = false;
this.newUserRoles = [];
this.newUserRoles = [];
}










save(roles){

console.log("saving in model");

console.log("saving in model");
return this._permissionsApiService.save(roles).then(() => {
console.log("saving in model success");
this.dirty = false;
this.newUserRoles = [];
console.log("saving in model success");
this.dirty = false;
this.newUserRoles = [];
Expand Down

0 comments on commit b05c894

Please sign in to comment.