Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
arsnova-click-v2-frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
ARSnova
arsnova-click-v2-frontend
Commits
c21247a6
Commit
c21247a6
authored
Nov 21, 2019
by
Christopher Fullarton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensures that the local db is loaded before initializing the app
parent
51d34251
Pipeline
#34038
passed with stages
in 15 minutes and 11 seconds
Changes
14
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
131 additions
and
88 deletions
+131
-88
quiz-duplicate.component.ts
src/app/quiz/quiz-duplicate/quiz-duplicate.component.ts
+4
-4
voting.component.ts
src/app/quiz/quiz-flow/voting/voting.component.ts
+1
-1
quiz-join.component.ts
src/app/quiz/quiz-join/quiz-join.component.ts
+9
-7
quiz-overview.component.ts
src/app/quiz/quiz-overview/quiz-overview.component.ts
+10
-10
root.module.ts
src/app/root.module.ts
+14
-0
home.component.ts
src/app/root/home/home.component.ts
+5
-9
root.component.ts
src/app/root/root/root.component.ts
+3
-0
attendee.service.ts
src/app/service/attendee/attendee.service.ts
+2
-2
i18n.service.ts
src/app/service/i18n/i18n.service.ts
+3
-8
init-db.guard.spec.ts
src/app/service/init-db-guard/init-db.guard.spec.ts
+15
-0
init-db.guard.ts
src/app/service/init-db-guard/init-db.guard.ts
+18
-0
quiz.service.ts
src/app/service/quiz/quiz.service.ts
+2
-2
themes.service.ts
src/app/service/themes/themes.service.ts
+3
-8
user.service.ts
src/app/service/user/user.service.ts
+42
-37
No files found.
src/app/quiz/quiz-duplicate/quiz-duplicate.component.ts
View file @
c21247a6
import
{
Component
,
OnDestroy
,
OnInit
}
from
'
@angular/core
'
;
import
{
ActivatedRoute
,
Router
}
from
'
@angular/router
'
;
import
{
Subject
}
from
'
rxjs
'
;
import
{
distinctUntilChanged
,
filter
,
map
,
switchMap
To
,
takeUntil
}
from
'
rxjs/operators
'
;
import
{
distinctUntilChanged
,
filter
,
map
,
switchMap
,
takeUntil
}
from
'
rxjs/operators
'
;
import
{
QuizEntity
}
from
'
../../lib/entities/QuizEntity
'
;
import
{
UserRole
}
from
'
../../lib/enums/UserRole
'
;
import
{
QuizApiService
}
from
'
../../service/api/quiz/quiz-api.service
'
;
...
...
@@ -28,18 +28,18 @@ export class QuizDuplicateComponent implements OnInit, OnDestroy {
public
ngOnInit
():
void
{
this
.
route
.
paramMap
.
pipe
(
map
(
params
=>
params
.
get
(
'
name
'
)),
filter
(()
=>
this
.
userService
.
isAuthorizedFor
(
UserRole
.
CreateQuiz
)),
distinctUntilChanged
(),
switchMap
To
(
this
.
quizApiService
.
initQuizInstance
(
name
)),
takeUntil
(
this
.
_destroy
))
distinctUntilChanged
(),
switchMap
(
name
=>
this
.
quizApiService
.
initQuizInstance
(
name
)),
takeUntil
(
this
.
_destroy
))
.
subscribe
(
async
data
=>
{
await
this
.
storageService
.
db
.
Quiz
.
put
(
data
.
payload
.
quiz
);
this
.
quizService
.
quiz
=
new
QuizEntity
(
data
.
payload
.
quiz
);
this
.
quizService
.
isOwner
=
true
;
console
.
log
(
'
router navigate duplicate
'
);
this
.
router
.
navigate
([
'
/quiz
'
,
'
flow
'
]);
},
()
=>
{
this
.
router
.
navigate
([
'
/
'
]);
});
}
public
ngOnDestroy
():
void
{
console
.
log
(
'
ondestroy duplicate
'
);
this
.
_destroy
.
next
();
this
.
_destroy
.
complete
();
}
...
...
src/app/quiz/quiz-flow/voting/voting.component.ts
View file @
c21247a6
...
...
@@ -151,7 +151,7 @@ export class VotingComponent implements OnInit, OnDestroy, IHasTriggeredNavigati
if
(
data
.
status
!==
StatusProtocol
.
Success
)
{
console
.
log
(
'
VotingComponent: PutResponse failed
'
,
data
);
}
});
}
,
()
=>
{}
);
}
public
initData
():
void
{
...
...
src/app/quiz/quiz-join/quiz-join.component.ts
View file @
c21247a6
import
{
Component
,
Inject
,
OnDestroy
,
OnInit
,
PLATFORM_ID
}
from
'
@angular/core
'
;
import
{
ActivatedRoute
,
Router
}
from
'
@angular/router
'
;
import
{
Subject
}
from
'
rxjs
'
;
import
{
distinctUntilChanged
,
filter
,
map
,
switchMapTo
,
takeUntil
}
from
'
rxjs/operators
'
;
import
{
DbState
}
from
'
../../lib/enums/enums
'
;
import
{
distinctUntilChanged
,
map
,
takeUntil
}
from
'
rxjs/operators
'
;
import
{
MessageProtocol
,
StatusProtocol
}
from
'
../../lib/enums/Message
'
;
import
{
IMessage
}
from
'
../../lib/interfaces/communication/IMessage
'
;
import
{
QuizApiService
}
from
'
../../service/api/quiz/quiz-api.service
'
;
...
...
@@ -28,8 +27,7 @@ export class QuizJoinComponent implements OnInit, OnDestroy {
private
router
:
Router
,
private
casService
:
CasLoginService
,
private
themesService
:
ThemesService
,
private
quizApiService
:
QuizApiService
,
private
sharedService
:
SharedService
,
private
storageService
:
StorageService
,
private
quizApiService
:
QuizApiService
,
private
sharedService
:
SharedService
,
private
storageService
:
StorageService
,
)
{
}
...
...
@@ -46,18 +44,22 @@ export class QuizJoinComponent implements OnInit, OnDestroy {
this
.
sharedService
.
isLoadingEmitter
.
next
(
true
);
const
quizData$
=
this
.
quizApiService
.
getFullQuizStatusData
(
quizname
);
this
.
storageService
.
stateNotifier
.
pipe
(
filter
(
val
=>
val
===
DbState
.
Initialized
),
distinctUntilChanged
(),
switchMapTo
(
quizData$
),
takeUntil
(
this
.
_destroy
)).
subscribe
(
quizStatusData
=>
this
.
resolveQuizStatusData
(
quizStatusData
));
this
.
quizApiService
.
getFullQuizStatusData
(
quizname
).
subscribe
(
data
=>
{
this
.
resolveQuizStatusData
(
data
);
},
()
=>
{
this
.
router
.
navigate
([
'
/
'
]);
});
});
}
public
ngOnDestroy
():
void
{
console
.
log
(
'
ondestroy
'
);
this
.
_destroy
.
next
();
this
.
_destroy
.
complete
();
}
private
resolveQuizStatusData
(
quizStatusData
:
IMessage
):
void
{
console
.
log
(
'
resolevstatus
'
,
quizStatusData
);
if
(
quizStatusData
.
status
!==
StatusProtocol
.
Success
||
quizStatusData
.
step
!==
MessageProtocol
.
Available
)
{
this
.
router
.
navigate
([
'
/
'
]);
return
;
...
...
src/app/quiz/quiz-overview/quiz-overview.component.ts
View file @
c21247a6
...
...
@@ -6,7 +6,6 @@ import { environment } from '../../../environments/environment';
import
{
QuizEntity
}
from
'
../../lib/entities/QuizEntity
'
;
import
{
MessageProtocol
,
StatusProtocol
}
from
'
../../lib/enums/Message
'
;
import
{
UserRole
}
from
'
../../lib/enums/UserRole
'
;
import
{
IMessage
}
from
'
../../lib/interfaces/communication/IMessage
'
;
import
{
QuizSaveComponent
}
from
'
../../modals/quiz-save/quiz-save.component
'
;
import
{
QuizApiService
}
from
'
../../service/api/quiz/quiz-api.service
'
;
import
{
ConnectionService
}
from
'
../../service/connection/connection.service
'
;
...
...
@@ -157,18 +156,19 @@ export class QuizOverviewComponent implements OnInit {
return
;
}
this
.
quizApiService
.
deleteQuiz
(
elem
).
subscribe
(
(
response
:
IMessage
)
=>
{
this
.
quizApiService
.
deleteQuiz
(
elem
).
subscribe
(
response
=>
{
if
(
response
.
status
!==
StatusProtocol
.
Success
)
{
console
.
log
(
'
QuizOverviewComponent: DeleteQuiz failed
'
,
response
);
}
else
{
const
sessionName
=
elem
.
name
;
this
.
storageService
.
db
.
Quiz
.
delete
(
sessionName
).
then
(()
=>
{
const
index
=
this
.
sessions
.
findIndex
(
quiz
=>
quiz
.
name
===
sessionName
);
if
(
index
>
-
1
)
{
this
.
sessions
.
splice
(
index
,
1
);
}
});
return
;
}
const
sessionName
=
elem
.
name
;
this
.
storageService
.
db
.
Quiz
.
delete
(
sessionName
).
then
(()
=>
{
const
index
=
this
.
sessions
.
findIndex
(
quiz
=>
quiz
.
name
===
sessionName
);
if
(
index
>
-
1
)
{
this
.
sessions
.
splice
(
index
,
1
);
}
});
});
}
...
...
src/app/root.module.ts
View file @
c21247a6
...
...
@@ -27,6 +27,7 @@ import { LoginComponent } from './root/login/login.component';
import
{
RootComponent
}
from
'
./root/root/root.component
'
;
import
{
ThemeSwitcherComponent
}
from
'
./root/theme-switcher/theme-switcher.component
'
;
import
rxStompConfig
from
'
./rx-stomp.config
'
;
import
{
InitDbGuard
}
from
'
./service/init-db-guard/init-db.guard
'
;
import
{
StaticLoginService
}
from
'
./service/login/static-login.service
'
;
import
{
SentryErrorHandler
}
from
'
./shared/sentry-error-handler
'
;
import
{
SharedModule
}
from
'
./shared/shared.module
'
;
...
...
@@ -36,50 +37,63 @@ const appRoutes: Routes = [
path
:
'
admin
'
,
canLoad
:
[
StaticLoginService
],
loadChildren
:
()
=>
import
(
'
./admin/admin.module
'
).
then
(
m
=>
m
.
AdminModule
),
canActivate
:
[
InitDbGuard
],
},
{
path
:
'
info
'
,
loadChildren
:
()
=>
import
(
'
./root/info/info.module
'
).
then
(
m
=>
m
.
InfoModule
),
canActivate
:
[
InitDbGuard
],
},
{
path
:
'
i18n-manager
'
,
canLoad
:
[
StaticLoginService
],
loadChildren
:
()
=>
import
(
'
./i18n-manager/i18n-manager.module
'
).
then
(
m
=>
m
.
I18nManagerModule
),
canActivate
:
[
InitDbGuard
],
},
{
path
:
'
quiz/manager
'
,
loadChildren
:
()
=>
import
(
'
./quiz/quiz-manager/quiz-manager.module
'
).
then
(
m
=>
m
.
QuizManagerModule
),
canActivate
:
[
InitDbGuard
],
},
{
path
:
'
quiz/flow
'
,
loadChildren
:
()
=>
import
(
'
./quiz/quiz-flow/quiz-flow.module
'
).
then
(
m
=>
m
.
QuizFlowModule
),
data
:
{
preload
:
false
,
},
canActivate
:
[
InitDbGuard
],
},
{
path
:
'
quiz
'
,
loadChildren
:
()
=>
import
(
'
./quiz/quiz.module
'
).
then
(
m
=>
m
.
QuizModule
),
canActivate
:
[
InitDbGuard
],
},
{
path
:
'
nicks
'
,
loadChildren
:
()
=>
import
(
'
./root/nickname-chooser/nickname-chooser.module
'
).
then
(
m
=>
m
.
NicknameChooserModule
),
data
:
{
preload
:
false
,
},
canActivate
:
[
InitDbGuard
],
},
{
path
:
'
themes
'
,
component
:
ThemeSwitcherComponent
,
canActivate
:
[
InitDbGuard
],
},
{
path
:
'
preview/:themeId/:languageId
'
,
component
:
HomeComponent
,
canActivate
:
[
InitDbGuard
],
},
{
path
:
'
languages
'
,
component
:
LanguageSwitcherComponent
,
canActivate
:
[
InitDbGuard
],
},
{
path
:
'
login
'
,
component
:
LoginComponent
,
canActivate
:
[
InitDbGuard
],
},
{
path
:
''
,
component
:
HomeComponent
,
pathMatch
:
'
full
'
,
canActivate
:
[
InitDbGuard
],
},
{
path
:
'
**
'
,
redirectTo
:
'
/
'
,
canActivate
:
[
InitDbGuard
],
},
];
...
...
src/app/root/home/home.component.ts
View file @
c21247a6
...
...
@@ -4,7 +4,7 @@ import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import
{
ActivatedRoute
,
Router
}
from
'
@angular/router
'
;
import
{
NgbModal
}
from
'
@ng-bootstrap/ng-bootstrap
'
;
import
{
Subject
}
from
'
rxjs
'
;
import
{
distinctUntilChanged
,
filter
,
switchMapTo
,
takeUntil
}
from
'
rxjs/operators
'
;
import
{
distinctUntilChanged
,
takeUntil
}
from
'
rxjs/operators
'
;
import
{
environment
}
from
'
../../../environments/environment
'
;
import
{
checkABCDOrdering
}
from
'
../../lib/checkABCDOrdering
'
;
import
{
DefaultSettings
}
from
'
../../lib/default.settings
'
;
...
...
@@ -12,7 +12,7 @@ import { AbstractAnswerEntity } from '../../lib/entities/answer/AbstractAnswerEn
import
{
DefaultAnswerEntity
}
from
'
../../lib/entities/answer/DefaultAnswerEntity
'
;
import
{
ABCDSingleChoiceQuestionEntity
}
from
'
../../lib/entities/question/ABCDSingleChoiceQuestionEntity
'
;
import
{
QuizEntity
}
from
'
../../lib/entities/QuizEntity
'
;
import
{
DbState
,
Language
,
StorageKey
}
from
'
../../lib/enums/enums
'
;
import
{
Language
,
StorageKey
}
from
'
../../lib/enums/enums
'
;
import
{
MessageProtocol
,
StatusProtocol
}
from
'
../../lib/enums/Message
'
;
import
{
QuestionType
}
from
'
../../lib/enums/QuestionType
'
;
import
{
QuizState
}
from
'
../../lib/enums/QuizState
'
;
...
...
@@ -140,11 +140,9 @@ export class HomeComponent implements OnInit, OnDestroy {
this
.
canUsePublicQuizzes
=
!
environment
.
requireLoginToCreateQuiz
||
(
isLoggedIn
&&
this
.
userService
.
isAuthorizedFor
(
UserRole
.
CreateQuiz
));
});
const
params$
=
this
.
activatedRoute
.
paramMap
.
pipe
(
distinctUntilChanged
(),
takeUntil
(
this
.
_destroy
));
const
state$
=
this
.
storageService
.
stateNotifier
.
pipe
(
filter
(
val
=>
val
!==
DbState
.
Destroy
),
distinctUntilChanged
(),
takeUntil
(
this
.
_destroy
));
state$
.
pipe
(
filter
(
state
=>
state
===
DbState
.
Initialized
)).
subscribe
(()
=>
{
this
.
activatedRoute
.
paramMap
.
pipe
(
distinctUntilChanged
(),
takeUntil
(
this
.
_destroy
)).
subscribe
(
async
params
=>
{
this
.
cleanUpSessionStorage
();
this
.
storageService
.
db
.
getAllQuiznames
().
then
(
quizNames
=>
{
this
.
_ownQuizzes
=
quizNames
;
...
...
@@ -164,9 +162,7 @@ export class HomeComponent implements OnInit, OnDestroy {
this
.
ownPublicQuizAmount
=
val
;
});
}
});
state$
.
pipe
(
switchMapTo
(
params$
)).
subscribe
(
async
params
=>
{
if
(
!
Object
.
keys
(
params
).
length
||
!
params
.
get
(
'
themeId
'
)
||
!
params
.
get
(
'
languageId
'
))
{
const
theme
=
this
.
storageService
.
db
.
Config
.
get
(
StorageKey
.
DefaultTheme
);
if
(
!
theme
)
{
...
...
@@ -490,7 +486,7 @@ export class HomeComponent implements OnInit, OnDestroy {
console
.
error
(
'
Invalid quiz status response in home component
'
,
value
);
}
}
});
}
,
()
=>
{}
);
}
private
cleanUpSessionStorage
():
void
{
...
...
src/app/root/root/root.component.ts
View file @
c21247a6
...
...
@@ -93,6 +93,9 @@ export class RootComponent implements OnInit, AfterViewInit {
}
});
this
.
themeService
.
initTheme
();
this
.
i18nService
.
initLanguage
();
this
.
storageService
.
stateNotifier
.
pipe
(
filter
(
val
=>
val
!==
DbState
.
Destroy
),
takeUntil
(
this
.
_destroy
)).
subscribe
(()
=>
{
this
.
themeService
.
updateCurrentlyUsedTheme
();
});
...
...
src/app/service/attendee/attendee.service.ts
View file @
c21247a6
...
...
@@ -136,7 +136,7 @@ export class AttendeeService {
}
private
restoreMembers
():
Promise
<
void
>
{
return
new
Promise
<
void
>
(
resolve
=>
{
return
new
Promise
<
void
>
(
(
resolve
,
reject
)
=>
{
this
.
memberApiService
.
getMembers
(
this
.
quizService
.
quiz
.
name
).
subscribe
((
data
)
=>
{
if
(
!
data
||
!
data
.
payload
)
{
return
;
...
...
@@ -147,7 +147,7 @@ export class AttendeeService {
});
this
.
footerBarService
.
footerElemStartQuiz
.
isActive
=
this
.
_attendees
.
length
>
0
;
resolve
();
});
}
,
()
=>
reject
()
);
});
}
...
...
src/app/service/i18n/i18n.service.ts
View file @
c21247a6
import
{
isPlatformBrowser
,
isPlatformServer
}
from
'
@angular/common
'
;
import
{
Inject
,
Injectable
,
PLATFORM_ID
}
from
'
@angular/core
'
;
import
{
TranslateService
}
from
'
@ngx-translate/core
'
;
import
{
filter
}
from
'
rxjs/operators
'
;
import
{
CurrencyType
,
DbState
,
Language
,
NumberType
,
StorageKey
}
from
'
../../lib/enums/enums
'
;
import
{
CurrencyType
,
Language
,
NumberType
,
StorageKey
}
from
'
../../lib/enums/enums
'
;
import
{
StorageService
}
from
'
../storage/storage.service
'
;
@
Injectable
({
...
...
@@ -29,11 +28,7 @@ export class I18nService {
this
.
_currentLanguage
=
value
;
}
constructor
(@
Inject
(
PLATFORM_ID
)
private
platformId
:
Object
,
private
translateService
:
TranslateService
,
private
storageService
:
StorageService
)
{
this
.
storageService
.
stateNotifier
.
pipe
(
filter
(
state
=>
state
===
DbState
.
Initialized
)).
subscribe
(()
=>
{
this
.
initLanguage
();
});
}
constructor
(@
Inject
(
PLATFORM_ID
)
private
platformId
:
Object
,
private
translateService
:
TranslateService
,
private
storageService
:
StorageService
)
{}
public
formatNumber
(
number
:
number
,
type
:
NumberType
=
NumberType
.
Decimal
,
locale
?:
string
):
string
{
if
(
isNaN
(
number
))
{
...
...
@@ -87,7 +82,7 @@ export class I18nService {
});
}
p
rivate
initLanguage
():
void
{
p
ublic
initLanguage
():
void
{
if
(
isPlatformServer
(
this
.
platformId
))
{
this
.
setLanguage
(
Language
.
EN
);
return
;
...
...
src/app/service/init-db-guard/init-db.guard.spec.ts
0 → 100644
View file @
c21247a6
import
{
inject
,
TestBed
}
from
'
@angular/core/testing
'
;
import
{
InitDbGuard
}
from
'
./init-db.guard
'
;
describe
(
'
InitDbGuard
'
,
()
=>
{
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({
providers
:
[
InitDbGuard
],
});
});
it
(
'
should ...
'
,
inject
([
InitDbGuard
],
(
guard
:
InitDbGuard
)
=>
{
expect
(
guard
).
toBeTruthy
();
}));
});
src/app/service/init-db-guard/init-db.guard.ts
0 → 100644
View file @
c21247a6
import
{
Injectable
}
from
'
@angular/core
'
;
import
{
CanActivate
}
from
'
@angular/router
'
;
import
{
Observable
}
from
'
rxjs
'
;
import
{
filter
,
map
}
from
'
rxjs/operators
'
;
import
{
DbState
}
from
'
../../lib/enums/enums
'
;
import
{
StorageService
}
from
'
../storage/storage.service
'
;
@
Injectable
({
providedIn
:
'
root
'
,
})
export
class
InitDbGuard
implements
CanActivate
{
constructor
(
private
storageService
:
StorageService
)
{}
public
canActivate
():
Observable
<
boolean
>
{
return
this
.
storageService
.
stateNotifier
.
pipe
(
filter
(
val
=>
val
===
DbState
.
Initialized
),
map
(()
=>
true
));
}
}
src/app/service/quiz/quiz.service.ts
View file @
c21247a6
...
...
@@ -182,7 +182,7 @@ export class QuizService {
this
.
isOwner
=
!!
quiz
;
console
.
log
(
'
QuizService: isOwner
'
,
this
.
isOwner
);
this
.
restoreSettings
(
quizName
).
then
(()
=>
resolve
());
});
})
.
catch
(()
=>
reject
())
;
});
}
...
...
@@ -225,7 +225,7 @@ export class QuizService {
this
.
quiz
=
response
.
payload
.
quiz
;
resolve
();
});
}
,
()
=>
reject
()
);
});
}
}
src/app/service/themes/themes.service.ts
View file @
c21247a6
import
{
isPlatformBrowser
,
isPlatformServer
}
from
'
@angular/common
'
;
import
{
EventEmitter
,
Inject
,
Injectable
,
PLATFORM_ID
}
from
'
@angular/core
'
;
import
{
filter
}
from
'
rxjs/operators
'
;
import
{
environment
}
from
'
../../../environments/environment
'
;
import
{
themes
}
from
'
../../lib/available-themes
'
;
import
{
DbState
,
StorageKey
}
from
'
../../lib/enums/enums
'
;
import
{
StorageKey
}
from
'
../../lib/enums/enums
'
;
import
{
MessageProtocol
,
StatusProtocol
}
from
'
../../lib/enums/Message
'
;
import
{
QuizTheme
}
from
'
../../lib/enums/QuizTheme
'
;
import
{
ITheme
}
from
'
../../lib/interfaces/ITheme
'
;
...
...
@@ -48,10 +47,6 @@ export class ThemesService {
this
.
_defaultTheme
=
environment
.
darkModeCheckEnabled
&&
//
window
.
matchMedia
(
'
(prefers-color-scheme: dark)
'
).
matches
?
//
QuizTheme
.
Blackbeauty
:
environment
.
defaultTheme
;
this
.
storageService
.
stateNotifier
.
pipe
(
filter
(
val
=>
val
===
DbState
.
Initialized
)).
subscribe
(()
=>
{
this
.
initTheme
();
});
}
public
async
updateCurrentlyUsedTheme
():
Promise
<
void
>
{
...
...
@@ -112,10 +107,10 @@ export class ThemesService {
this
.
addNewNode
(
elem
);
}
});
});
}
,
()
=>
{}
);
}
p
rivate
initTheme
():
void
{
p
ublic
initTheme
():
void
{
if
(
isPlatformBrowser
(
this
.
platformId
))
{
this
.
storageService
.
db
.
Config
.
get
(
StorageKey
.
DefaultTheme
).
then
(
val
=>
{
...
...
src/app/service/user/user.service.ts
View file @
c21247a6
...
...
@@ -87,36 +87,9 @@ export class UserService {
private
jwtHelper
:
JwtHelperService
,
private
quizService
:
QuizService
,
)
{
this
.
storageService
.
stateNotifier
.
pipe
(
filter
(
type
=>
this
.
username
!==
DbName
.
Default
&&
type
!==
null
&&
type
!==
DbState
.
Destroy
))
.
subscribe
(()
=>
{
if
(
this
.
_staticLoginTokenContent
&&
this
.
_staticLoginTokenContent
.
privateKey
)
{
console
.
log
(
'
UserService: having static token content with private key
'
);
this
.
storageService
.
db
.
Config
.
put
({
type
:
StorageKey
.
PrivateKey
,
value
:
this
.
_staticLoginTokenContent
.
privateKey
,
});
sessionStorage
.
setItem
(
StorageKey
.
PrivateKey
,
this
.
_staticLoginTokenContent
.
privateKey
);
if
(
this
.
_tmpRemoteQuizData
.
length
)
{
console
.
log
(
'
UserService: having remote quiz data
'
);
this
.
storageService
.
db
.
Quiz
.
toCollection
().
filter
(
localQuiz
=>
!
this
.
_tmpRemoteQuizData
.
find
(
val
=>
val
.
name
===
localQuiz
.
name
))
.
each
(
localQuiz
=>
{
console
.
log
(
'
UserService: syncing local quiz data to server
'
);
this
.
quizService
.
persistQuiz
(
new
QuizEntity
(
localQuiz
));
}).
then
(()
=>
{
this
.
_tmpRemoteQuizData
.
forEach
(
quiz
=>
{
this
.
quizService
.
persistQuiz
(
new
QuizEntity
(
quiz
));
console
.
log
(
'
UserService: persisting remote quiz to local db
'
,
quiz
.
name
);
});
});
}
else
{
console
.
log
(
'
UserService: not received remote quiz data
'
);
}
}
else
{
console
.
log
(
'
UserService: not received any static login token content
'
);
}
this
.
reloadState
();
});
this
.
loadConfig
();
...
...
@@ -135,15 +108,18 @@ export class UserService {
}
public
authenticateThroughCas
(
token
:
string
):
Promise
<
boolean
>
{
return
new
Promise
(
async
resolve
=>
{
const
data
=
await
this
.
authorizeApiService
.
getAuthorizationForToken
(
token
).
toPromise
();
if
(
data
.
status
===
StatusProtocol
.
Success
)
{
this
.
_casTicket
=
data
.
payload
.
casTicket
;
this
.
isLoggedIn
=
true
;
resolve
(
true
);
}
else
{
this
.
isLoggedIn
=
false
;
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
try
{
const
data
=
await
this
.
authorizeApiService
.
getAuthorizationForToken
(
token
).
toPromise
();
if
(
data
.
status
===
StatusProtocol
.
Success
)
{
this
.
_casTicket
=
data
.
payload
.
casTicket
;
this
.
isLoggedIn
=
true
;
resolve
(
true
);
}
else
{
this
.
isLoggedIn
=
false
;
resolve
(
false
);
}
}
catch
(
e
)
{
resolve
(
false
);
}
});
...
...
@@ -232,6 +208,35 @@ export class UserService {
return
this
.
staticLoginTokenContent
.
userAuthorizations
.
includes
(
authorization
);
}
private
reloadState
():
void
{
if
(
this
.
_staticLoginTokenContent
&&
this
.
_staticLoginTokenContent
.
privateKey
)
{
console
.
log
(
'
UserService: having static token content with private key
'
);
this
.
storageService
.
db
.
Config
.
put
({
type
:
StorageKey
.
PrivateKey
,
value
:
this
.
_staticLoginTokenContent
.
privateKey
,
});
sessionStorage
.
setItem
(
StorageKey
.
PrivateKey
,
this
.
_staticLoginTokenContent
.
privateKey
);
if
(
this
.
_tmpRemoteQuizData
.
length
)
{
console
.
log
(
'
UserService: having remote quiz data
'
);
this
.
storageService
.
db
.
Quiz
.
toCollection
().
filter
(
localQuiz
=>
!
this
.
_tmpRemoteQuizData
.
find
(
val
=>
val
.
name
===
localQuiz
.
name
))
.
each
(
localQuiz
=>
{
console
.
log
(
'
UserService: syncing local quiz data to server
'
);
this
.
quizService
.
persistQuiz
(
new
QuizEntity
(
localQuiz
));
}).
then
(()
=>
{
this
.
_tmpRemoteQuizData
.
forEach
(
quiz
=>
{
this
.
quizService
.
persistQuiz
(
new
QuizEntity
(
quiz
));
console
.
log
(
'
UserService: persisting remote quiz to local db
'
,
quiz
.
name
);
});
});
}
else
{
console
.
log
(
'
UserService: not received remote quiz data
'
);
}
}
else
{
console
.
log
(
'
UserService: not received any static login token content
'
);
}
}
private
loadConfig
():
boolean
{
if
(
isPlatformServer
(
this
.
platformId
))
{
this
.
isLoggedIn
=
false
;
...
...
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