Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
whats-open-web
Commits
d4b3f299
Commit
d4b3f299
authored
Apr 25, 2017
by
mdsecurity
Browse files
checking special schedules now
parent
4b5b83c9
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/app/data-provider.service.ts
View file @
d4b3f299
...
...
@@ -6,6 +6,7 @@ import { Subject } from 'rxjs/Subject';
import
{
Place
}
from
'
./place
'
;
import
{
Day
}
from
'
./day
'
;
import
{
Time
}
from
'
./time
'
;
import
{
SpecialSchedule
}
from
'
./special-schedule
'
;
// Operators
import
'
rxjs/add/observable/throw
'
;
import
'
rxjs/add/operator/catch
'
;
...
...
@@ -26,31 +27,31 @@ export class DataProviderService {
constructor
(
private
http
:
Http
)
{
}
getFacilities
():
Observable
<
Place
[]
>
{
console
.
log
(
"
I was called
"
);
if
(
this
.
places
)
{
return
Observable
.
of
(
this
.
places
);
}
else
if
(
this
.
placesObs
)
{
return
this
.
placesObs
;
}
else
{
const
facilities
=
localStorage
.
getItem
(
'
facilities
'
);
if
(
facilities
)
{
this
.
places
=
this
.
extractData
(
JSON
.
parse
(
faciliti
es
)
)
;
this
.
placesObs
=
Observable
.
of
(
this
.
places
)
;
return
this
.
placesObs
;
}
else
{
this
.
placesObs
=
this
.
http
.
get
(
this
.
Url
)
.
map
((
data
)
=>
{
this
.
placesObs
=
null
;
data
=
data
.
json
();
this
.
places
=
this
.
extractData
(
data
);
this
.
contextPlace
=
this
.
places
[
0
];
localStorage
.
setItem
(
'
facilities
'
,
JSON
.
stringify
(
data
));
return
this
.
places
;
})
.
catch
(
this
.
handleError
).
share
();
return
this
.
placesObs
;
}
}
// if (this.places) {
// return Observable.of
(this.places)
;
// } else if
(this.places
Obs) {
// return
this.placesObs
;
// } else {
// const facilities = localStorage.getItem('facilities');
// if (
facilities
) {
// this.places = this.extractData(JSON.parse
(facilities)
);
//
this.places
Obs = Observable.of(this.plac
es);
// return
this.placesObs;
// } else {
this
.
placesObs
=
this
.
http
.
get
(
this
.
Url
)
.
map
((
data
)
=>
{
this
.
placesObs
=
null
;
data
=
data
.
json
();
this
.
places
=
this
.
extractData
(
data
);
this
.
contextPlace
=
this
.
places
[
0
];
localStorage
.
setItem
(
'
facilities
'
,
JSON
.
stringify
(
data
));
return
this
.
places
;
})
.
catch
(
this
.
handleError
).
share
();
return
this
.
placesObs
;
//
}
//
}
}
getContext
():
Observable
<
Place
>
{
return
this
.
contextSubj
.
asObservable
();
...
...
@@ -70,8 +71,8 @@ export class DataProviderService {
const
places
:
Place
[]
=
[];
// const data = res.json();
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
cons
t
main_schedule_times
:
Day
[]
=
[];
le
t
main_schedule_times
:
Day
[]
=
[];
let
special_schedules
:
SpecialSchedule
[]
=
[];
for
(
let
e
=
0
;
e
<
data
[
i
].
main_schedule
.
open_times
.
length
;
e
++
)
{
let
jsonDay
=
data
[
i
].
main_schedule
.
open_times
[
e
];
...
...
@@ -85,7 +86,26 @@ export class DataProviderService {
parseTime
(
jsonDay
.
end_time
));
main_schedule_times
.
push
(
Object
.
freeze
(
day
));
}
for
(
let
e
=
0
;
e
<
data
[
i
].
special_schedules
.
length
;
e
++
)
{
const
jsonSchedule
=
data
[
i
].
special_schedules
[
e
];
let
open_times
:
Day
[]
=
[];
for
(
let
f
=
0
;
f
<
jsonSchedule
.
open_times
.
length
;
f
++
){
let
jsonDay
=
jsonSchedule
.
open_times
[
f
];
const
day
=
new
Day
(
jsonDay
.
id
,
jsonDay
.
last_modified
,
jsonDay
.
schedule
,
jsonDay
.
start_day
,
parseTime
(
jsonDay
.
start_time
),
jsonDay
.
end_day
,
parseTime
(
jsonDay
.
end_time
));
open_times
.
push
(
Object
.
freeze
(
day
));
}
const
schedule
=
new
SpecialSchedule
(
jsonSchedule
.
valid_start
,
jsonSchedule
.
valid_end
,
open_times
);
special_schedules
.
push
(
Object
.
freeze
(
schedule
));
}
console
.
log
(
special_schedules
);
places
.
push
(
new
Place
(
main_schedule_times
,
[],
...
...
src/app/place.ts
View file @
d4b3f299
import
{
Day
}
from
'
./day
'
;
import
{
Time
}
from
'
./time
'
;
import
{
SpecialSchedule
}
from
'
./special-schedule
'
;
export
class
Place
{
main_schedule_times
:
Day
[]
=
[];
special_schedule
_times
=
[];
special_schedule
s
:
SpecialSchedule
[]
=
[];
id
:
number
;
last_modified
:
string
;
name
:
string
;
category
:
number
;
location
:
string
;
constructor
(
main_schedule_times
?:
Day
[],
special_schedule
_times
?
,
id
?:
number
,
last_modified
?:
string
,
constructor
(
main_schedule_times
?:
Day
[],
special_schedule
s
?:
SpecialSchedule
[]
,
id
?:
number
,
last_modified
?:
string
,
name
?:
string
,
category
?:
number
,
location
?:
string
)
{
this
.
main_schedule_times
=
main_schedule_times
||
[];
this
.
special_schedule
_time
s
=
special_schedule
_time
s
||
[];
this
.
special_schedules
=
special_schedules
||
[];
this
.
id
=
id
||
0
;
this
.
last_modified
=
last_modified
||
''
;
this
.
name
=
name
||
''
;
...
...
@@ -76,5 +77,5 @@ export class Place {
}
}
}
// useSpecial():
src/app/special-schedule.ts
0 → 100644
View file @
d4b3f299
import
{
Day
}
from
'
./day
'
;
import
{
Time
}
from
'
./time
'
;
export
class
SpecialSchedule
{
open_times
:
Day
[];
valid_start
:
string
;
valid_end
:
string
;
constructor
(
valid_start
:
string
,
valid_end
:
string
,
open_times
?:
Day
[]){
this
.
open_times
=
open_times
||
[];
this
.
valid_end
=
valid_end
;
this
.
valid_start
=
valid_start
;
}
}
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