code improvements
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
|
||||
<rb-icon-button icon="add" mode="primary" (click)="addNewUser()" class="space-below">New user</rb-icon-button>
|
||||
|
||||
<form *ngIf="newUser" #userForm="ngForm" class="space-below">
|
||||
|
@ -1,53 +1,5 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { UsersComponent } from './users.component';
|
||||
import {ApiService} from '../services/api.service';
|
||||
import {LoginService} from '../services/login.service';
|
||||
import {ModalService} from '@inst-iot/bosch-angular-ui-components';
|
||||
import {RbCustomInputsModule} from '../rb-custom-inputs/rb-custom-inputs.module';
|
||||
|
||||
// TODO
|
||||
|
||||
let apiServiceSpy: jasmine.SpyObj<ApiService>;
|
||||
let modalServiceSpy: jasmine.SpyObj<ModalService>;
|
||||
let loginServiceSpy: jasmine.SpyObj<LoginService>;
|
||||
|
||||
|
||||
describe('UsersComponent', () => {
|
||||
let component: UsersComponent;
|
||||
let fixture: ComponentFixture<UsersComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
const apiSpy = jasmine.createSpyObj('ApiService', ['get', 'post', 'put']);
|
||||
const modalSpy = jasmine.createSpyObj('ModalService', ['open']);
|
||||
const loginSpy = jasmine.createSpyObj('LoginService', ['login', 'canActivate']);
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ UsersComponent ],
|
||||
imports: [
|
||||
RbCustomInputsModule
|
||||
],
|
||||
providers: [
|
||||
{provide: ApiService, useValue: apiSpy},
|
||||
{provide: ModalService, useValue: modalSpy},
|
||||
{provide: LoginService, useValue: loginSpy},
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
apiServiceSpy = TestBed.inject(ApiService) as jasmine.SpyObj<ApiService>;
|
||||
modalServiceSpy = TestBed.inject(ModalService) as jasmine.SpyObj<ModalService>;
|
||||
loginServiceSpy = TestBed.inject(LoginService) as jasmine.SpyObj<LoginService>;
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(UsersComponent);
|
||||
component = fixture.componentInstance;
|
||||
component.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
@ -13,12 +13,12 @@ import {DataService} from '../services/data.service';
|
||||
})
|
||||
export class UsersComponent implements OnInit {
|
||||
|
||||
users: UserModel[] = [];
|
||||
deletedUsers: UserModel[] = [];
|
||||
newUser: UserModel | null = null;
|
||||
newUserPass = '';
|
||||
modelSelect: {id: string, name: string}[] = [];
|
||||
modelIds: {[id: string]: string} = {};
|
||||
users: UserModel[] = []; // all active users
|
||||
deletedUsers: UserModel[] = []; // all deleted users
|
||||
newUser: UserModel | null = null; // data of new user
|
||||
newUserPass = ''; // password of new user
|
||||
modelSelect: {id: string, name: string}[] = []; // list of all models for selection
|
||||
modelIds: {[id: string]: string} = {}; // all models by id
|
||||
|
||||
constructor(
|
||||
private api: ApiService,
|
||||
@ -41,9 +41,7 @@ export class UsersComponent implements OnInit {
|
||||
}
|
||||
|
||||
saveUser(user: UserModel) {
|
||||
console.log(user.models);
|
||||
user.models = user.models.filter(e => e !== '');
|
||||
console.log(user.models);
|
||||
this.api.put<UserModel>('/user/' + user.origName, user.sendFormat('admin'), data => {
|
||||
user.deserialize(data);
|
||||
user.edit = false;
|
||||
@ -51,7 +49,7 @@ export class UsersComponent implements OnInit {
|
||||
}
|
||||
|
||||
saveNewUser() {
|
||||
// this.newUser.models = this.newUser.models.filter(e => e !== '' || e !== undefined);
|
||||
this.newUser.models = this.newUser.models.filter(e => e !== '');
|
||||
this.api.post('/user/new', {...this.newUser.sendFormat('admin'), pass: this.newUserPass}, data => {
|
||||
this.newUser = null;
|
||||
this.users.push(new UserModel().deserialize(data));
|
||||
|
Reference in New Issue
Block a user