Skip to content

Commit ccd3074

Browse files
author
Ihor Khomiak
committed
Merge additional branch to master
2 parents 2dbfdb2 + c82477d commit ccd3074

File tree

7 files changed

+25
-35
lines changed

7 files changed

+25
-35
lines changed

app/common/utils.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
export class Utils {
22

3-
public static dateToYMDWithMonthName(date) {
4-
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
5-
const d = date.getDate();
6-
const m = monthNames[date.getMonth()];
7-
const y = date.getFullYear();
8-
return y + ' ' + m + ' ' + (d <= 9 ? '0' + d : d);
9-
}
10-
113
public static dateToYMD(date) {
12-
const d = date.getDate();
13-
const y = date.getFullYear();
14-
const m = (date.getMonth()+1);
15-
return y + '-' + (m <= 9 ? '0' + m : m) + '-' + (d <= 9 ? '0' + d : d);
4+
let strArray=['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
5+
let d = date.getDate();
6+
let m = strArray[date.getMonth()];
7+
let y = date.getFullYear();
8+
return '' + (d <= 9 ? '0' + d : d) + ' ' + m + ' ' + y;
169
}
1710

1811
public static formatDateString(dateString: string): string {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.main-container {
2-
height: 100%;
3-
width: 100%;
1+
.main-container {
2+
height: 100%;
3+
width: 100%;
44
}

app/components/cost/costs.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class CostsComponent implements OnInit {
2323
@Input() set dateRange(value: any) {
2424
this._dateRange = value;
2525
if(value['startDate']) {
26+
console.log(JSON.stringify(value));
2627
this.filterData(value);
2728
}
2829
}
@@ -63,7 +64,7 @@ export class CostsComponent implements OnInit {
6364
let cost: Cost = new Cost();
6465
cost.quantity = Number(textField.text);
6566
cost.type = "No Type";
66-
cost.changesDate = Utils.dateToYMD(new Date());
67+
cost.changesDate = (new Date()).toISOString();
6768
cost.changesMonth = Utils.getMonthAndYear(new Date());
6869
cost.isFavorite = false;
6970

app/components/cost/edit/cost-edit.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { RouterExtensions } from 'nativescript-angular/router';
44

55
import { CostService } from '../../../services/cost.service';
66
import { Cost } from '../../../common/protocol';
7-
import { Utils } from '../../../common/utils';
87
import { DatePicker } from 'tns-core-modules/ui/date-picker/date-picker';
8+
import { Utils } from '../../../common/utils';
99

1010
@Component({
1111
selector: "cost-edit",
@@ -46,7 +46,7 @@ export class CostEditComponent implements OnInit {
4646
}
4747

4848
onDoneButtonTap(): void {
49-
this.costForUpdate.changesDate = (new Date(this.costDate)).toDateString();
49+
this.costForUpdate.changesDate = (new Date(this.costDate)).toISOString();
5050
this.costForUpdate.changesMonth = Utils.getMonthAndYear(new Date(this.costDate));
5151

5252
this.costService.updateCost(this.costForUpdate).then(result => {

app/components/list/list.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ export class ListComponent {
3636
private getDateValue(item) {
3737
let currentDate: Date = new Date(Date.now());
3838
let itemDate: Date = new Date(item.changesDate);
39-
// if(currentDate.toDateString() === itemDate.toDateString()) {
40-
// return ("0" + itemDate.getHours()).slice(-2) + ":" + ("0" + itemDate.getMinutes()).slice(-2);
41-
// }
42-
return Utils.dateToYMDWithMonthName(itemDate);
39+
if(currentDate.toDateString() === itemDate.toDateString()) {
40+
return ("0" + itemDate.getHours()).slice(-2) + ":" + ("0" + itemDate.getMinutes()).slice(-2);
41+
}
42+
return Utils.dateToYMD(itemDate);
4343
}
4444
}

app/services/cost.service.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import firebase = require('nativescript-plugin-firebase');
55
import { Cost } from '../common/protocol';
66
import { Config } from "../common/config";
77
import { Utils } from "../common/utils";
8-
import { Observable } from "tns-core-modules/ui/editable-text-base/editable-text-base";
98

109
@Injectable()
1110
export class CostService {
1211
private _costs: ObservableArray<any> = new ObservableArray();
12+
private userid = Config.getUserToken();
1313
private listeners;
1414

1515
get costs(): ObservableArray<any> {
@@ -21,10 +21,9 @@ export class CostService {
2121
return new Promise(function(success, error) {
2222
firebase.addValueEventListener(
2323
(result) => {
24-
console.log('objectToArray: ', JSON.stringify(result));
2524
that._costs = new ObservableArray(that.objectToArray(result.value));
2625
return success();
27-
}, `/${Config.getUserToken()}/costs`).then(
26+
}, `/${this.userid}/costs`).then(
2827
listenerWrapper => that.listeners = listenerWrapper.listeners
2928
);
3029
}.bind(this));
@@ -41,21 +40,18 @@ export class CostService {
4140
ranges: [
4241
{
4342
type: firebase.QueryRangeType.START_AT,
44-
value: Utils.dateToYMD(new Date(dateRange.startDate))
43+
value: (new Date(dateRange.startDate)).toISOString()
4544
},
4645
{
4746
type: firebase.QueryRangeType.END_AT,
48-
value: Utils.dateToYMD(new Date(dateRange.endDate))
47+
value: Utils.increaseDateByOneDay(dateRange.endDate)
4948
}
5049
]
5150
};
5251

53-
console.log(JSON.stringify(parameters));
54-
5552
return new Promise(function(success, error) {
5653
firebase.query(
5754
result => {
58-
console.log('objectToArray: ', JSON.stringify(result));
5955
that._costs = new ObservableArray(that.objectToArray(result.value));
6056
return success();
6157
},
@@ -70,18 +66,18 @@ export class CostService {
7066
}
7167

7268
addCost(newCost: Cost) {
73-
firebase.push(`/${Config.getUserToken()}/costs`, newCost).then(result => {
69+
firebase.push(`/${this.userid}/costs`, newCost).then(result => {
7470
newCost.id = result.key;
7571
this._costs.unshift(newCost);
7672
});
7773
}
7874

7975
updateCost(costForUpdate: Cost) {
80-
return firebase.update(`/${Config.getUserToken()}/costs/${costForUpdate.id}`, costForUpdate);
76+
return firebase.update(`/${this.userid}/costs/${costForUpdate.id}`, costForUpdate);
8177
}
8278

8379
deleteCost(costForDelete: Cost) {
84-
firebase.remove(`/${Config.getUserToken()}/costs/${costForDelete.id}`).then(result => {
80+
firebase.remove(`/${this.userid}/costs/${costForDelete.id}`).then(result => {
8581
const index = this._costs.indexOf(costForDelete);
8682
this._costs.splice(index, 1);
8783
alert(costForDelete.quantity + " removed!");
@@ -91,7 +87,7 @@ export class CostService {
9187
removeListeners() {
9288
firebase.removeEventListeners(
9389
this.listeners,
94-
`/${Config.getUserToken()}/costs`
90+
`/${this.userid}/costs`
9591
);
9692
}
9793

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@
3939
"nativescript-dev-typescript": "~0.5.0",
4040
"typescript": "~2.2.1"
4141
}
42-
}
42+
}

0 commit comments

Comments
 (0)