Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UsersDojoNg
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LNGCodingDojo
UsersDojoNg
Commits
a58b4900
Commit
a58b4900
authored
Mar 24, 2017
by
Harangozó Péter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
compatibility
compatible with both .net and node backend
parent
bf4a9e1d
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
195 additions
and
73 deletions
+195
-73
app.module.ts
src/app/app.module.ts
+2
-1
right.ts
src/app/modules/rights/models/right.ts
+1
-1
right.component.html
src/app/modules/rights/right/right.component.html
+2
-2
rights.component.html
src/app/modules/rights/rights.component.html
+1
-1
right.service.ts
src/app/modules/rights/services/right.service.ts
+12
-4
user.ts
src/app/modules/users/models/user.ts
+6
-5
user.service.ts
src/app/modules/users/services/user.service.ts
+6
-6
user.component.html
src/app/modules/users/user/user.component.html
+66
-37
user.component.ts
src/app/modules/users/user/user.component.ts
+86
-12
users.component.html
src/app/modules/users/users.component.html
+3
-3
styles.less
src/styles.less
+10
-1
No files found.
src/app/app.module.ts
View file @
a58b4900
//built in angular modules
//built in angular modules
import
{
BrowserModule
}
from
'@angular/platform-browser'
;
import
{
BrowserModule
}
from
'@angular/platform-browser'
;
import
{
NgModule
}
from
'@angular/core'
;
import
{
NgModule
}
from
'@angular/core'
;
import
{
FormsModule
}
from
'@angular/forms'
;
import
{
HttpModule
}
from
'@angular/http'
;
import
{
HttpModule
}
from
'@angular/http'
;
import
{
FormsModule
,
ReactiveFormsModule
}
from
'@angular/forms'
;
//external modules
//external modules
import
{
NgbModule
}
from
'@ng-bootstrap/ng-bootstrap'
;
import
{
NgbModule
}
from
'@ng-bootstrap/ng-bootstrap'
;
...
@@ -30,6 +30,7 @@ import { RightService } from './modules/rights/services/right.service';
...
@@ -30,6 +30,7 @@ import { RightService } from './modules/rights/services/right.service';
imports
:
[
imports
:
[
BrowserModule
,
BrowserModule
,
FormsModule
,
FormsModule
,
ReactiveFormsModule
,
HttpModule
,
HttpModule
,
AppRoutingModule
,
AppRoutingModule
,
NgbModule
.
forRoot
(),
NgbModule
.
forRoot
(),
...
...
src/app/modules/rights/models/right.ts
View file @
a58b4900
export
class
Right
{
export
class
Right
{
id
:
string
;
id
:
string
;
N
ame
:
string
;
n
ame
:
string
;
}
}
src/app/modules/rights/right/right.component.html
View file @
a58b4900
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
<div
class=
"form-group row"
>
<div
class=
"form-group row"
>
<label
for=
"Name"
class=
"col-2 col-form-label"
>
Name
</label>
<label
for=
"Name"
class=
"col-2 col-form-label"
>
Name
</label>
<div
class=
"col-10"
>
<div
class=
"col-10"
>
<input
id=
"Name"
class=
"form-control"
type=
"text"
[(
ngModel
)]="
right
.
N
ame
"
placeholder=
"Name"
/>
<input
id=
"Name"
class=
"form-control"
type=
"text"
[(
ngModel
)]="
right
.
n
ame
"
placeholder=
"Name"
/>
</div>
</div>
</div>
</div>
</div>
</div>
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
<label
for=
"Name"
class=
"col-2 col-form-label"
>
Name
</label>
<label
for=
"Name"
class=
"col-2 col-form-label"
>
Name
</label>
<div
class=
"col-10"
>
<div
class=
"col-10"
>
<p
class=
"form-control-static"
>
<p
class=
"form-control-static"
>
{{right.
N
ame}}
{{right.
n
ame}}
</p>
</p>
</div>
</div>
</div>
</div>
...
...
src/app/modules/rights/rights.component.html
View file @
a58b4900
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
<tbody>
<tbody>
<tr
*
ngFor=
"let right of rights"
>
<tr
*
ngFor=
"let right of rights"
>
<th
scope=
"row"
>
{{right.id}}
</th>
<th
scope=
"row"
>
{{right.id}}
</th>
<td>
{{right.
N
ame}}
</td>
<td>
{{right.
n
ame}}
</td>
<td>
<td>
<button
type=
"button"
class=
"btn btn-sm btn-outline-info"
(
click
)="
details
(
right
.
id
)"
>
Details
</button>
<button
type=
"button"
class=
"btn btn-sm btn-outline-info"
(
click
)="
details
(
right
.
id
)"
>
Details
</button>
<button
type=
"button"
class=
"btn btn-sm btn-outline-warning"
(
click
)="
edit
(
right
.
id
)"
>
Edit
</button>
<button
type=
"button"
class=
"btn btn-sm btn-outline-warning"
(
click
)="
edit
(
right
.
id
)"
>
Edit
</button>
...
...
src/app/modules/rights/services/right.service.ts
View file @
a58b4900
...
@@ -16,10 +16,18 @@ export class RightService {
...
@@ -16,10 +16,18 @@ export class RightService {
)
{
}
)
{
}
getRights
():
Promise
<
Right
[]
>
{
getRights
():
Promise
<
Right
[]
>
{
return
this
.
http
.
get
(
this
.
rightsUrl
)
.
toPromise
()
.
then
(
response
=>
response
.
json
()
as
Right
[])
;
}
getRightsForCombo
():
Promise
<
Right
[]
>
{
return
this
.
http
.
get
(
this
.
rightsUrl
+
"/get-rights-for-combo"
)
return
this
.
http
.
get
(
this
.
rightsUrl
+
"/get-rights-for-combo"
)
.
toPromise
()
.
toPromise
()
.
then
(
response
=>
.
then
(
response
=>
response
.
json
()
.
rights
as
Right
[])
response
.
json
()
as
Right
[])
;
;
}
}
...
@@ -27,14 +35,14 @@ export class RightService {
...
@@ -27,14 +35,14 @@ export class RightService {
const
url
=
`
${
this
.
rightsUrl
}
/
${
id
}
`
;
const
url
=
`
${
this
.
rightsUrl
}
/
${
id
}
`
;
return
this
.
http
.
get
(
url
)
return
this
.
http
.
get
(
url
)
.
toPromise
()
.
toPromise
()
.
then
(
response
=>
response
.
json
()
.
right
as
Right
);
.
then
(
response
=>
response
.
json
()
as
Right
);
}
}
createRight
(
right
:
Right
):
Promise
<
Right
>
{
createRight
(
right
:
Right
):
Promise
<
Right
>
{
return
this
.
http
return
this
.
http
.
post
(
this
.
rightsUrl
,
JSON
.
stringify
(
right
),
{
headers
:
this
.
headers
})
.
post
(
this
.
rightsUrl
,
JSON
.
stringify
(
right
),
{
headers
:
this
.
headers
})
.
toPromise
()
.
toPromise
()
.
then
(
res
=>
res
.
json
()
.
right
)
.
then
(
res
=>
res
.
json
())
.
catch
(
this
.
handleError
);
.
catch
(
this
.
handleError
);
}
}
...
@@ -42,7 +50,7 @@ export class RightService {
...
@@ -42,7 +50,7 @@ export class RightService {
return
this
.
http
return
this
.
http
.
put
(
this
.
rightsUrl
,
JSON
.
stringify
(
right
),
{
headers
:
this
.
headers
})
.
put
(
this
.
rightsUrl
,
JSON
.
stringify
(
right
),
{
headers
:
this
.
headers
})
.
toPromise
()
.
toPromise
()
.
then
(
res
=>
res
.
json
()
.
right
)
.
then
(
res
=>
res
.
json
())
.
catch
(
this
.
handleError
);
.
catch
(
this
.
handleError
);
}
}
...
...
src/app/modules/users/models/user.ts
View file @
a58b4900
export
class
User
{
export
class
User
{
id
:
number
;
id
:
number
;
BirthDate
:
any
;
birthDate
:
any
;
FirstName
:
string
;
firstName
:
string
;
LastName
:
string
;
lastName
:
string
;
UserName
:
string
;
userName
:
string
;
Rights
:
any
[];
rights
:
any
[];
rightsDisplay
:
string
;
}
}
src/app/modules/users/services/user.service.ts
View file @
a58b4900
...
@@ -19,7 +19,7 @@ export class UserService {
...
@@ -19,7 +19,7 @@ export class UserService {
return
this
.
http
.
get
(
this
.
usersUrl
)
return
this
.
http
.
get
(
this
.
usersUrl
)
.
toPromise
()
.
toPromise
()
.
then
(
response
=>
.
then
(
response
=>
response
.
json
()
.
users
as
User
[])
response
.
json
()
as
User
[])
;
;
}
}
...
@@ -28,8 +28,8 @@ export class UserService {
...
@@ -28,8 +28,8 @@ export class UserService {
return
this
.
http
.
get
(
url
)
return
this
.
http
.
get
(
url
)
.
toPromise
()
.
toPromise
()
.
then
(
response
=>
{
.
then
(
response
=>
{
let
user
=
response
.
json
()
.
user
as
User
;
let
user
=
response
.
json
()
as
User
;
user
.
BirthDate
=
this
.
parserFormatter
.
parse
(
user
.
B
irthDate
);
user
.
birthDate
=
this
.
parserFormatter
.
parse
(
user
.
b
irthDate
);
return
user
;
return
user
;
});
});
}
}
...
@@ -42,7 +42,7 @@ export class UserService {
...
@@ -42,7 +42,7 @@ export class UserService {
}
}
createUser
(
user
:
User
):
Promise
<
User
>
{
createUser
(
user
:
User
):
Promise
<
User
>
{
user
.
BirthDate
=
this
.
parserFormatter
.
format
(
user
.
B
irthDate
);
user
.
birthDate
=
this
.
parserFormatter
.
format
(
user
.
b
irthDate
);
return
this
.
http
return
this
.
http
.
post
(
this
.
usersUrl
,
JSON
.
stringify
(
user
),
{
headers
:
this
.
headers
})
.
post
(
this
.
usersUrl
,
JSON
.
stringify
(
user
),
{
headers
:
this
.
headers
})
.
toPromise
()
.
toPromise
()
...
@@ -51,12 +51,12 @@ export class UserService {
...
@@ -51,12 +51,12 @@ export class UserService {
}
}
updateUser
(
user
:
User
):
Promise
<
User
>
{
updateUser
(
user
:
User
):
Promise
<
User
>
{
user
.
BirthDate
=
this
.
parserFormatter
.
format
(
user
.
B
irthDate
);
user
.
birthDate
=
this
.
parserFormatter
.
format
(
user
.
b
irthDate
);
return
this
.
http
return
this
.
http
.
put
(
this
.
usersUrl
,
JSON
.
stringify
(
user
),
{
headers
:
this
.
headers
})
.
put
(
this
.
usersUrl
,
JSON
.
stringify
(
user
),
{
headers
:
this
.
headers
})
.
toPromise
()
.
toPromise
()
.
then
(
res
=>
{
.
then
(
res
=>
{
return
res
.
json
()
.
user
;
return
res
.
json
();
})
})
.
catch
(
this
.
handleError
);
.
catch
(
this
.
handleError
);
}
}
...
...
src/app/modules/users/user/user.component.html
View file @
a58b4900
...
@@ -5,45 +5,66 @@
...
@@ -5,45 +5,66 @@
<button
type=
"button"
class=
"btn btn-sm btn-outline-success float-right"
(
click
)="
save
()"
[
hidden
]="!
editMode
"
>
Save
</button>
<button
type=
"button"
class=
"btn btn-sm btn-outline-success float-right"
(
click
)="
save
()"
[
hidden
]="!
editMode
"
>
Save
</button>
<hr>
<hr>
<div
*
ngIf=
"editMode"
>
<div
*
ngIf=
"editMode"
>
<div
class=
"form-group row"
>
<form
class=
"form"
[
formGroup
]="
userForm
"
(
ngSubmit
)="
save
()"
>
<label
for=
"first-name"
class=
"col-2 col-form-label"
>
Firstname
</label>
<div
class=
"form-group row"
>
<div
class=
"col-10"
>
<label
for=
"first-name"
class=
"col-2 col-form-label"
>
Firstname
</label>
<input
id=
"first-name"
class=
"form-control"
type=
"text"
[(
ngModel
)]="
user
.
FirstName
"
placeholder=
"Firstname"
/>
<div
class=
"col-10"
>
<input
id=
"first-name"
class=
"form-control"
type=
"text"
formControlName=
"firstName"
[(
ngModel
)]="
user
.
firstName
"
placeholder=
"Firstname"
required
/>
<div
*
ngIf=
"formErrors.firstName"
class=
"alert alert-danger"
>
{{ formErrors.firstName }}
</div>
</div>
</div>
</div>
</div>
<div
class=
"form-group row"
>
<div
class=
"form-group row"
>
<label
for=
"last-name"
class=
"col-2 col-form-label"
>
Lastname
</label>
<label
for=
"last-name"
class=
"col-2 col-form-label"
>
Lastname
</label>
<div
class=
"col-10"
>
<div
class=
"col-10"
>
<input
id=
"last-name"
class=
"form-control"
type=
"text"
formControlName=
"lastName"
[(
ngModel
)]="
user
.
lastName
"
placeholder=
"Lastname"
<input
id=
"last-name"
class=
"form-control"
type=
"text"
[(
ngModel
)]="
user
.
LastName
"
placeholder=
"Lastname"
/>
required
/>
<div
*
ngIf=
"formErrors.lastName"
class=
"alert alert-danger"
>
{{ formErrors.lastName }}
</div>
</div>
</div>
</div>
</div>
<div
class=
"form-group row"
>
<div
class=
"form-group row"
>
<label
for=
"user-name"
class=
"col-2 col-form-label"
>
Username
</label>
<label
for=
"user-name"
class=
"col-2 col-form-label"
>
Username
</label>
<div
class=
"col-10"
>
<div
class=
"col-10"
>
<input
id=
"user-name"
class=
"form-control"
type=
"text"
formControlName=
"userName"
[(
ngModel
)]="
user
.
userName
"
placeholder=
"Username"
<input
id=
"user-name"
class=
"form-control"
type=
"text"
[(
ngModel
)]="
user
.
UserName
"
placeholder=
"Username"
/>
required
/>
<div
*
ngIf=
"formErrors.userName"
class=
"alert alert-danger"
>
{{ formErrors.userName }}
</div>
</div>
</div>
</div>
</div>
<div
class=
"form-group row"
>
<div
class=
"form-group row"
>
<label
for=
"birthdate"
class=
"col-2 col-form-label"
>
Birthdate
</label>
<label
for=
"birthdate"
class=
"col-2 col-form-label"
>
Birthdate
</label>
<div
class=
"col-10 input-group"
>
<div
class=
"col-10 input-group"
>
<input
class=
"form-control"
placeholder=
"yyyy-mm-dd"
name=
"dp"
formControlName=
"birthDate"
[(
ngModel
)]="
user
.
birthDate
"
ngbDatepicker
<input
class=
"form-control"
placeholder=
"yyyy-mm-dd"
name=
"dp"
[(
ngModel
)]="
user
.
BirthDate
"
ngbDatepicker
#
d=
"ngbDatepicker"
>
required
#
d=
"ngbDatepicker"
>
<div
class=
"input-group-addon"
(
click
)="
d
.
toggle
()"
>
<div
class=
"input-group-addon"
(
click
)="
d
.
toggle
()"
>
<i
class=
"fa fa-6 fa-calendar"
aria-hidden=
"true"
style=
"width: 1.2rem; height: 1rem; cursor: pointer;"
></i>
<i
class=
"fa fa-6 fa-calendar"
aria-hidden=
"true"
style=
"width: 1.2rem; height: 1rem; cursor: pointer;"
></i>
</div>
<div
*
ngIf=
"formErrors.birthDate"
class=
"alert alert-danger"
>
{{ formErrors.birthDate }}
</div>
</div>
</div>
</div>
</div>
</div>
<div
class=
"form-group row"
>
<div
class=
"form-group row"
>
<label
for=
"birthdate"
class=
"col-2 col-form-label"
>
Rights
</label>
<label
for=
"birthdate"
class=
"col-2 col-form-label"
>
Rights
</label>
<div
class=
"col-10"
>
<div
class=
"col-10"
>
<ng-select
<ng-select
formControlName=
"rights"
[
items
]="
rights
"
[
items
]="
rights
"
[
multiple
]="
true
"
[
multiple
]="
true
"
(
selected
)="
selectedRight
($
event
)"
(
selected
)="
selectedRight
($
event
)"
(
removed
)="
removedRight
($
event
)"
(
removed
)="
removedRight
($
event
)"
[
active
]="
user
.
Rights
"
[
active
]="
user
.
rights
"
placeholder=
"No rights selected"
></ng-select>
placeholder=
"No rights selected"
></ng-select>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
<div
*
ngIf=
"!editMode"
>
<div
*
ngIf=
"!editMode"
>
...
@@ -51,7 +72,7 @@
...
@@ -51,7 +72,7 @@
<label
for=
"first-name"
class=
"col-2 col-form-label"
>
Firstname
</label>
<label
for=
"first-name"
class=
"col-2 col-form-label"
>
Firstname
</label>
<div
class=
"col-10"
>
<div
class=
"col-10"
>
<p
class=
"form-control-static"
>
<p
class=
"form-control-static"
>
{{user.
F
irstName}}
{{user.
f
irstName}}
</p>
</p>
</div>
</div>
</div>
</div>
...
@@ -59,7 +80,7 @@
...
@@ -59,7 +80,7 @@
<label
for=
"last-name"
class=
"col-2 col-form-label"
>
Lastname
</label>
<label
for=
"last-name"
class=
"col-2 col-form-label"
>
Lastname
</label>
<div
class=
"col-10"
>
<div
class=
"col-10"
>
<p
class=
"form-control-static"
>
<p
class=
"form-control-static"
>
{{user.
L
astName}}
{{user.
l
astName}}
</p>
</p>
</div>
</div>
</div>
</div>
...
@@ -67,7 +88,7 @@
...
@@ -67,7 +88,7 @@
<label
for=
"user-name"
class=
"col-2 col-form-label"
>
Username
</label>
<label
for=
"user-name"
class=
"col-2 col-form-label"
>
Username
</label>
<div
class=
"col-10"
>
<div
class=
"col-10"
>
<p
class=
"form-control-static"
>
<p
class=
"form-control-static"
>
{{user.
U
serName}}
{{user.
u
serName}}
</p>
</p>
</div>
</div>
</div>
</div>
...
@@ -75,7 +96,15 @@
...
@@ -75,7 +96,15 @@
<label
for=
"birthdate"
class=
"col-2 col-form-label"
>
Birthdate
</label>
<label
for=
"birthdate"
class=
"col-2 col-form-label"
>
Birthdate
</label>
<div
class=
"col-10 input-group"
>
<div
class=
"col-10 input-group"
>
<p
class=
"form-control-static"
>
<p
class=
"form-control-static"
>
{{parserFormatter.format(user.BirthDate)}}
{{parserFormatter.format(user.birthDate)}}
</p>
</div>
</div>
<div
class=
"form-group row"
>
<label
for=
"rights"
class=
"col-2 col-form-label"
>
Rights
</label>
<div
class=
"col-10 input-group"
>
<p
class=
"form-control-static"
>
{{user.rightsDisplay}}
</p>
</p>
</div>
</div>
</div>
</div>
...
...
src/app/modules/users/user/user.component.ts
View file @
a58b4900
...
@@ -2,6 +2,7 @@ import 'rxjs/add/operator/switchMap';
...
@@ -2,6 +2,7 @@ import 'rxjs/add/operator/switchMap';
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
ActivatedRoute
,
Params
}
from
'@angular/router'
;
import
{
ActivatedRoute
,
Params
}
from
'@angular/router'
;
import
{
Location
}
from
'@angular/common'
;
import
{
Location
}
from
'@angular/common'
;
import
{
FormGroup
,
FormControl
,
FormBuilder
,
Validators
}
from
'@angular/forms'
;
import
{
NgbDateParserFormatter
}
from
'@ng-bootstrap/ng-bootstrap'
;
import
{
NgbDateParserFormatter
}
from
'@ng-bootstrap/ng-bootstrap'
;
import
{
User
}
from
'../models/user'
;
import
{
User
}
from
'../models/user'
;
...
@@ -19,40 +20,113 @@ export class UserComponent implements OnInit {
...
@@ -19,40 +20,113 @@ export class UserComponent implements OnInit {
editMode
:
boolean
;
editMode
:
boolean
;
title
:
string
;
title
:
string
;
rights
:
any
[];
rights
:
any
[];
userForm
:
FormGroup
;
// = new FormGroup({
// firstName: new FormControl(),
// lastName: new FormControl(),
// userName: new FormControl(),
// birthDate: new FormControl(),
// rights: new FormControl(),
// });
constructor
(
constructor
(
private
userService
:
UserService
,
private
userService
:
UserService
,
private
rightService
:
RightService
,
private
rightService
:
RightService
,
private
route
:
ActivatedRoute
,
private
route
:
ActivatedRoute
,
private
location
:
Location
,
private
location
:
Location
,
private
parserFormatter
:
NgbDateParserFormatter
private
parserFormatter
:
NgbDateParserFormatter
,
private
fb
:
FormBuilder
)
{
}
)
{
}
selectedRight
(
selected
):
void
{
selectedRight
(
selected
):
void
{
this
.
user
.
Rights
=
this
.
user
.
R
ights
||
[];
this
.
user
.
rights
=
this
.
user
.
r
ights
||
[];
this
.
user
.
R
ights
.
push
(
selected
);
this
.
user
.
r
ights
.
push
(
selected
);
}
}
removedRight
(
selected
):
void
{
removedRight
(
selected
):
void
{
this
.
user
.
Rights
=
this
.
user
.
R
ights
||
[];
this
.
user
.
rights
=
this
.
user
.
r
ights
||
[];
var
found
=
this
.
user
.
R
ights
.
find
(
u
=>
u
.
id
==
selected
.
id
);
var
found
=
this
.
user
.
r
ights
.
find
(
u
=>
u
.
id
==
selected
.
id
);
var
index
=
this
.
user
.
R
ights
.
indexOf
(
found
);
var
index
=
this
.
user
.
r
ights
.
indexOf
(
found
);
if
(
index
>
-
1
)
if
(
index
>
-
1
)
this
.
user
.
R
ights
.
splice
(
index
,
1
);
this
.
user
.
r
ights
.
splice
(
index
,
1
);
}
}
ngOnInit
():
void
{
buildForm
():
void
{
this
.
rightService
.
getRights
().
then
(
rights
=>
this
.
rights
=
rights
);
this
.
userForm
=
this
.
fb
.
group
({
'firstName'
:
[
this
.
user
.
firstName
,
[
Validators
.
required
]],
'lastName'
:
[
this
.
user
.
lastName
,
[
Validators
.
required
]],
'userName'
:
[
this
.
user
.
userName
,
[
Validators
.
required
,
Validators
.
minLength
(
4
),
Validators
.
maxLength
(
24
)
]
],
'birthDate'
:
[
this
.
user
.
birthDate
,
[
Validators
.
required
]],
'rights'
:
[
this
.
user
.
rights
],
});
this
.
userForm
.
valueChanges
.
subscribe
(
data
=>
this
.
onValueChanged
(
data
));
this
.
onValueChanged
();
}
onValueChanged
(
data
?:
any
)
{
if
(
!
this
.
userForm
)
{
return
;
}
const
form
=
this
.
userForm
;
for
(
const
field
in
this
.
formErrors
)
{
// clear previous error message (if any)
this
.
formErrors
[
field
]
=
''
;
const
control
=
form
.
get
(
field
);
if
(
control
&&
control
.
dirty
&&
!
control
.
valid
)
{
const
messages
=
this
.
validationMessages
[
field
];
for
(
const
key
in
control
.
errors
)
{
this
.
formErrors
[
field
]
+=
messages
[
key
]
+
' '
;
}
}
}
}
formErrors
=
{
'firstName'
:
''
,
'lastName'
:
''
,
'userName'
:
''
,
'birthDate'
:
''
,
'rights'
:
''
,
};
validationMessages
=
{
'firstName'
:
{
'required'
:
'Firstname is required.'
,
},
'lastName'
:
{
'required'
:
'Lastname is required.'
,
},
'userName'
:
{
'required'
:
'Username is required.'
,
'minlength'
:
'Username must be at least 4 characters long.'
,
'maxlength'
:
'Username cannot be more than 24 characters long.'
,
},
'birthDate'
:
{
'required'
:
'Birth date is required.'
,
},
'rights'
:
{}
};
ngOnInit
():
void
{
this
.
rightService
.
getRightsForCombo
().
then
(
rights
=>
this
.
rights
=
rights
);
this
.
user
=
new
User
();
this
.
user
=
new
User
();
this
.
buildForm
();
this
.
editMode
=
true
;
this
.
editMode
=
true
;
this
.
route
.
params
.
subscribe
(
params
=>
{
this
.
route
.
params
.
subscribe
(
params
=>
{
if
(
params
[
'id'
])
{
if
(
params
[
'id'
])
{
this
.
userService
.
getUser
(
params
[
'id'
])
this
.
userService
.
getUser
(
params
[
'id'
])
.
then
(
user
=>
{
.
then
(
user
=>
{
this
.
user
=
user
this
.
user
=
user
this
.
user
.
Rights
=
this
.
user
.
Rights
||
[];
this
.
user
.
rights
=
this
.
user
.
rights
||
[];
this
.
user
.
rightsDisplay
=
this
.
user
.
rights
.
map
(
r
=>
r
.
text
).
join
(
', '
);
});
});
}
}
if
(
this
.
location
.
path
().
indexOf
(
'details'
)
>
-
1
)
{
if
(
this
.
location
.
path
().
indexOf
(
'details'
)
>
-
1
)
{
...
@@ -65,7 +139,7 @@ export class UserComponent implements OnInit {
...
@@ -65,7 +139,7 @@ export class UserComponent implements OnInit {
else
{
else
{
this
.
title
=
"Create"
;
this
.
title
=
"Create"
;
this
.
user
=
new
User
();
this
.
user
=
new
User
();
this
.
user
.
Rights
=
this
.
user
.
R
ights
||
[];
this
.
user
.
rights
=
this
.
user
.
r
ights
||
[];
}
}
}
}
});
});
...
...
src/app/modules/users/users.component.html
View file @
a58b4900
...
@@ -15,9 +15,9 @@
...
@@ -15,9 +15,9 @@
<tbody>
<tbody>
<tr
*
ngFor=
"let user of users"
>
<tr
*
ngFor=
"let user of users"
>
<th
scope=
"row"
>
{{user.id}}
</th>
<th
scope=
"row"
>
{{user.id}}
</th>
<td>
{{user.
F
irstName}}
</td>
<td>
{{user.
f
irstName}}
</td>
<td>
{{user.
L
astName}}
</td>
<td>
{{user.
l
astName}}
</td>
<td>
{{user.
U
serName}}
</td>
<td>
{{user.
u
serName}}
</td>
<td>
<td>
<button
type=
"button"
class=
"btn btn-sm btn-outline-info"
(
click
)="
details
(
user
.
id
)"
>
Details
</button>
<button
type=
"button"
class=
"btn btn-sm btn-outline-info"
(
click
)="
details
(
user
.
id
)"
>
Details
</button>
<button
type=
"button"
class=
"btn btn-sm btn-outline-warning"
(
click
)="
edit
(
user
.
id
)"
>
Edit
</button>
<button
type=
"button"
class=
"btn btn-sm btn-outline-warning"
(
click
)="
edit
(
user
.
id
)"
>
Edit
</button>
...
...
src/styles.less
View file @
a58b4900
...
@@ -4,9 +4,17 @@ ng-select{
...
@@ -4,9 +4,17 @@ ng-select{
display: block!important;
display: block!important;
}
}
}
}
//Because of bootstrap 4 removed xs from the button sizes
.btn-group-xs>.btn, .btn-xs {
.btn-group-xs>.btn, .btn-xs {
padding: .25rem .5rem;
padding: .25rem .5rem;
font-size: .875rem;
font-size: .875rem;
border-radius: .2rem;
border-radius: .2rem;
}
.ng-valid[required], .ng-valid.required {
border-left: 5px solid #42A948; /* green */
}
.ng-invalid:not(form) {
border-left: 5px solid #a94442; /* red */
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment