Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Codecrew
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
30
Merge Requests
2
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 05a1b193
authored
Apr 01, 2018
by
Antti Väyrynen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleaning
1 parent
e24385dc
Pipeline
#37
passed
in 0 seconds
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
43 deletions
code/moya-angular/src/app/components/moya-locale/moya-locale.component.ts
code/moya-angular/src/app/components/moya-locale/moya-locale.model.ts
code/moya-angular/src/app/components/moya-locale/moya-locale.service.ts
code/moya-angular/src/app/components/moya-locale/moya-locale.component.ts
View file @
05a1b19
...
...
@@ -2,13 +2,10 @@ import { Component, OnInit } from '@angular/core';
import
{
DEFAULT_LOCALE
,
MoyaLocaleService
}
from
'./moya-locale.service'
;
import
{
TranslateService
}
from
'@ngx-translate/core'
;
const
ENGLISH
=
'en'
;
const
FINNISH
=
'fi'
;
const
SWEDISH
=
'sv'
;
@
Component
({
selector
:
'moya-locale'
,
templateUrl
:
'./moya-locale.component.html'
,
...
...
@@ -30,7 +27,6 @@ export class MoyaLocaleComponent implements OnInit {
this
.
localeService
.
getUserLocale
().
subscribe
(
locale
=>
{
this
.
selectLocale
(
locale
);
}
);
}
selectLocale
(
locale
:
string
,
save
=
false
):
void
{
if
(
!
[
ENGLISH
,
FINNISH
,
SWEDISH
].
includes
(
locale
))
{
...
...
@@ -59,7 +55,6 @@ export class MoyaLocaleComponent implements OnInit {
}
selectEnglish
()
{
this
.
selectLocale
(
ENGLISH
,
true
);
}
...
...
@@ -71,8 +66,4 @@ export class MoyaLocaleComponent implements OnInit {
selectSwedish
()
{
this
.
selectLocale
(
SWEDISH
,
true
);
}
}
code/moya-angular/src/app/components/moya-locale/moya-locale.model.ts
View file @
05a1b19
export
class
MoyaLocale
{
public
userLocale
?:
string
;
public
eventLocale
?:
string
;
constructor
()
{
}
export
interface
MoyaLocale
{
userLocale
:
string
;
eventLocale
:
string
;
}
code/moya-angular/src/app/components/moya-locale/moya-locale.service.ts
View file @
05a1b19
...
...
@@ -8,14 +8,10 @@ import 'rxjs/add/operator/catch';
export
const
DEFAULT_LOCALE
=
'fi'
;
const
LOCALSTORAGE_NAME
=
'currently used locale code'
;
@
Injectable
()
export
class
MoyaLocaleService
{
constructor
(
private
http
:
HttpClient
)
{
}
/**
* Order of Locale:
* 1. User's locale from database
...
...
@@ -27,24 +23,25 @@ export class MoyaLocaleService {
*/
public
getUserLocale
():
Observable
<
string
>
{
return
this
.
http
.
get
<
MoyaLocale
>
(
MOYA_BASE_URL
+
'/v3/locale/'
).
catch
(
x
=>
Observable
.
of
(
new
MoyaLocale
())).
map
(
locale
=>
{
return
this
.
http
.
get
<
MoyaLocale
>
(
MOYA_BASE_URL
+
'/v3/locale/'
)
.
catch
(
x
=>
Observable
.
of
({}
as
MoyaLocale
))
.
map
(
locale
=>
{
if
(
locale
&&
locale
.
userLocale
)
{
return
locale
.
userLocale
;
}
if
(
locale
&&
locale
.
userLocale
)
{
return
locale
.
userLocale
;
}
const
storageLocale
=
localStorage
.
getItem
(
LOCALSTORAGE_NAME
);
const
storageLocale
=
localStorage
.
getItem
(
LOCALSTORAGE_NAME
);
if
(
storageLocale
)
{
return
storageLocale
;
}
if
(
storage
Locale
)
{
return
storage
Locale
;
}
if
(
locale
.
event
Locale
)
{
return
locale
.
event
Locale
;
}
if
(
locale
.
eventLocale
)
{
return
locale
.
eventLocale
;
}
return
DEFAULT_LOCALE
;
});
return
DEFAULT_LOCALE
;
});
}
...
...
@@ -53,20 +50,18 @@ export class MoyaLocaleService {
*
* There is no errors
* @param {string} locale
* @return {Promise<any>} This will return promise, but it will contain nothing.
*/
public
setUserLocale
(
locale
:
string
):
void
{
const
newLocale
:
MoyaLocale
=
new
MoyaLocale
();
newLocale
.
userLocale
=
locale
;
const
newLocale
:
MoyaLocale
=
{
userLocale
:
locale
,
eventLocale
:
undefined
};
// let's save locale to database, if it fails, we save it into localstorage. No errors to show for user.
this
.
http
.
post
(
MOYA_BASE_URL
+
'/v3/locale/'
,
newLocale
).
first
().
catch
(
x
=>
{
this
.
http
.
post
(
MOYA_BASE_URL
+
'/v3/locale/'
,
newLocale
).
catch
(
x
=>
{
localStorage
.
setItem
(
LOCALSTORAGE_NAME
,
locale
);
return
'ok'
;
}).
subscribe
();
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment