Skip to content

Commit

Permalink
1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
maxulyanov committed Apr 4, 2017
1 parent 0db5e6e commit 94f0084
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 65 deletions.
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.wheremoney264323" version="1.1.0" xmlns="http://www.w3.org/ns/widgets"
<widget id="com.ionicframework.wheremoney264323" version="1.2.0" xmlns="http://www.w3.org/ns/widgets"
xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Где деньги</name>
<description>Контроль ваших финансов</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ transaction-action-component {
bottom: 75px;
right: 0;
left: 0;
z-index: 5;
text-align: right;
.button {
height: 5.5rem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ export class TransactionForm {
if(this.eventType === EVENTS.ADD_TRANSACTION) {
let sum = data.sum;
if(this.type === '0') {
sum = parseInt('-' + sum);
if(data.inBudget) {
this.budgetService.updateRestBudget(sum);
}
sum = parseInt('-' + sum);
}
this.userService.updateBalance(sum);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<div class="fadeIn animated">
<div *ngIf="transaction.showLabelDate" class="b-transaction-date"><ion-icon name="ios-calendar-outline"></ion-icon> {{ dateCreated }}</div>
<div class="b-transaction-item {{ transactionClass }}">
<div class="transaction-item__data">
<div class="transaction-item__icon">
Expand Down
10 changes: 10 additions & 0 deletions src/components/transaction-item/transaction-item.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,13 @@ transaction-item-component {
font-size: 2.2rem;
}
}


.controls-item {
.button {
width: 60px;
ion-icon {
font-size: 2.2em;
}
}
}
26 changes: 0 additions & 26 deletions src/components/transaction-item/transaction-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export class TransactionItem {
@Input() transaction: TransactionInterface;


public dateCreated: string;
public categoryName: string;
public sum: string;
public transactionClass: string;
Expand All @@ -41,35 +40,10 @@ export class TransactionItem {
*/
public ngAfterContentInit(): void {
this.categoryName = this.transaction.name;
this.createDate();
this.createSum();
}


/**
*
*/
private createDate(): void {
let created = this.transaction.created;
let dayMs = 1000 * 60 * 60 * 24;
if (created) {
let date = Utils.dateFormatting(created);
if(date == Utils.dateFormatting(new Date())) {
this.dateCreated = 'сегодня';
}
else if(Utils.dateFormatting(created - dayMs) === Utils.dateFormatting(+new Date() - (dayMs * 2))) {
this.dateCreated = 'вчера';
}
else if(Utils.dateFormatting(created - dayMs) === Utils.dateFormatting(+new Date() - (dayMs * 3))) {
this.dateCreated = 'позавчера';
}
else {
this.dateCreated = date;
}
}
}


/**
*
*/
Expand Down
5 changes: 4 additions & 1 deletion src/interfaces/transaction.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


export interface TransactionInterface {
id: number,
category_id: number,
name: string,
created: number;
Expand All @@ -19,5 +20,7 @@ export interface TransactionInterface {
sum: number,
type: number,
showLabelDate: boolean,
inBudget: boolean
dateCreated: string,
inBudget: boolean,
canDeleted: boolean
}
18 changes: 14 additions & 4 deletions src/pages/activity/activity.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,21 @@
<ion-content>

<div class="container-activity-list" *ngIf="totalCount > 0">
<div class="grid-row">
<div class="grid-column-12 grid-padding grid-left" *ngFor="let transaction of transactions;">
<transaction-item-component [transaction]="transaction"></transaction-item-component>
<ion-list>
<div *ngFor="let transaction of transactions; let position = index;">
<div *ngIf="transaction.showLabelDate" class="b-transaction-date"><ion-icon name="ios-calendar-outline"></ion-icon> {{ transaction.dateCreated }}</div>
<ion-item-sliding>
<ion-item>
<transaction-item-component [transaction]="transaction"></transaction-item-component>
</ion-item>
<ion-item-options *ngIf="position < 5 && transaction.canDeleted" class="controls-item" side="right">
<button ion-button icon-only color="remove" (click)="deleteTransaction($event, transaction.id, position)">
<ion-icon name="ios-close"></ion-icon>
</button>
</ion-item-options>
</ion-item-sliding>
</div>
</div>
</ion-list>

</div>

Expand Down
103 changes: 91 additions & 12 deletions src/pages/activity/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@


import { Component } from '@angular/core';
import { Utils } from "../../libs/Utils";

import { DateService } from "../../services/date.service";
import { TransactionService } from "../../services/transaction.service";
import { BudgetService } from "../../services/budget.service";
import { UserService } from "../../services/user.service";
import { Utils } from "../../libs/Utils";
import { NotifyService } from "../../services/notify.service";

import { TransactionInterface } from "../../interfaces/transaction.interface";


@Component({
Expand Down Expand Up @@ -47,10 +51,14 @@ export class ActivityPage {
*
* @param dateService
* @param transactionService
* @param notifyService
* @param budgetService
* @param userService
*/
constructor(private dateService: DateService,
private transactionService: TransactionService,
private notifyService: NotifyService,
private budgetService: BudgetService,
private userService: UserService) {

this.title = 'Активность';
Expand Down Expand Up @@ -90,7 +98,7 @@ export class ActivityPage {
this.offset += this.stepOffset;
this.getTransactions().then(
(transactions)=> {
this.transactions = this.setShowLabelDate(Array.prototype.concat(this.transactions, transactions));
this.transactions = this.iteratorTransactions(Array.prototype.concat(this.transactions, transactions));
infiniteScroll.complete();
},
(error) => {
Expand Down Expand Up @@ -133,14 +141,13 @@ export class ActivityPage {
}



/**
*
*/
private renderTransactions(): void {
this.getTransactions().then(
(transactions)=> {
this.transactions = this.setShowLabelDate(Array.prototype.concat(this.transactions, transactions));
this.transactions = this.iteratorTransactions(Array.prototype.concat(this.transactions, transactions));
},
(error) => {
console.error(error);
Expand Down Expand Up @@ -174,21 +181,93 @@ export class ActivityPage {
/**
*
* @param transactions
* @returns {any[]}
* @returns {TransactionInterface[]}
*/
private setShowLabelDate(transactions: any[]): any[] {
let date = null;
private iteratorTransactions(transactions: TransactionInterface[]): TransactionInterface[] {
let savedDate = null;
return transactions.map((transaction) => {
let clearDate = new Date(transaction.created).setHours(0, 0, 0, 0);
if(clearDate != date) {
date = clearDate;
transaction.showLabelDate = true;
}
this.createDate(transaction);
this.setCanDeleted(transaction);
this.setShowLabelDate(transaction, savedDate, (newDate) => savedDate = newDate);
return transaction;
});
}


/**
*
* @param transaction
* @param savedDate
* @param changeDate
*/
private setShowLabelDate(transaction: TransactionInterface, savedDate, changeDate): void {
let clearDate = new Date(transaction.created).setHours(0, 0, 0, 0);
if(clearDate != savedDate) {
changeDate(clearDate);
transaction.showLabelDate = true;
}
}

/**
*
* @param transaction
*/
public setCanDeleted(transaction: TransactionInterface): void {
transaction.canDeleted = this.dateService.dateIsToday(new Date(transaction.created));
}


/**
*
* @param transaction
*/
private createDate(transaction: TransactionInterface): void {
const created = transaction.created;
const dayMs = 1000 * 60 * 60 * 24;

if (created) {
let date = Utils.dateFormatting(created);
if(date == Utils.dateFormatting(new Date())) {
transaction.dateCreated = 'сегодня';
}
else if(Utils.dateFormatting(created - dayMs) === Utils.dateFormatting(+new Date() - (dayMs * 2))) {
transaction.dateCreated = 'вчера';
}
else if(Utils.dateFormatting(created - dayMs) === Utils.dateFormatting(+new Date() - (dayMs * 3))) {
transaction.dateCreated = 'позавчера';
}
else {
transaction.dateCreated = date;
}
}
}


/**
*
* @param event
* @param id
* @param position
*/
public deleteTransaction(event: any, id: number, position: number): void {
event.stopPropagation();
this.transactionService.deleteTransaction(id).then((message: string) => {
const currentTransaction = this.transactions[position];
if(currentTransaction.inBudget && currentTransaction.type == 0) {
this.budgetService.updateRestBudget(currentTransaction.sum);
}

this.userService.updateBalance(currentTransaction.sum).then(() => this.updateBalance());

const copyTransactions = this.transactions.slice();
copyTransactions.splice(position, 1);
this.transactions = this.iteratorTransactions(copyTransactions);
this.notifyService.show(message);
});
}



/**
*
*/
Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class SettingPage {
private budgetService: BudgetService) {

this.title = 'Настройки';
this.version = '1.1.0';
this.version = '1.2.0';
this.settings = {
budget: {
value: '10000'
Expand Down
5 changes: 4 additions & 1 deletion src/pages/stats/stats.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ page-stats {
font-size: 1.3rem;
text-transform: uppercase;
.total-sum-s {
margin-left: 5px;
background: $secondColorContent;
padding: 8px 15px;
margin-left: 10px;
font-size: 1.7rem;
border-radius: 30px;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/pages/templates/templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
<div *ngIf="totalCount > 0">
<div class="container-templates-list">
<ion-list>
<ion-item-sliding *ngFor="let template of templates; let i = index;">
<ion-item-sliding *ngFor="let template of templates; let position = index;">
<ion-item>
<transaction-item-component [transaction]="template"></transaction-item-component>
</ion-item>
<ion-item-options class="controls-template" side="right">
<ion-item-options class="controls-item" side="right">
<button ion-button icon-only color="create" (click)="createTransaction($event, template.templateId)">
<ion-icon name="ios-add"></ion-icon>
</button>
<button ion-button icon-only color="update" (click)="updateTemplate($event, template)">
<ion-icon name="ios-refresh"></ion-icon>
</button>
<button ion-button icon-only color="remove" (click)="deleteTemplate($event, template.templateId, i)">
<button ion-button icon-only color="remove" (click)="deleteTemplate($event, template.templateId, position)">
<ion-icon name="ios-close"></ion-icon>
</button>
</ion-item-options>
Expand Down
8 changes: 0 additions & 8 deletions src/pages/templates/templates.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ page-templates {
}
}

.controls-template {
.button {
width: 60px;
ion-icon {
font-size: 2.2em;
}
}
}

.container-templates-list {
margin: 16px 0;
Expand Down
4 changes: 2 additions & 2 deletions src/services/budget.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export class BudgetService {
const { year, week } = this.dateService.getWeekNumber();

this.getBudget(year, week).then((budget: any) => {
const rest = budget.rest - value;
const promise = this.sqlService.query(`UPDATE budget SET rest = ${rest} WHERE week=${week}`);
const rest = budget.rest + value;
const promise = this.sqlService.query(`UPDATE budget SET rest = ${rest} WHERE year = ${year} AND week=${week}`);
promise.then(
(data) => {
resolve(data);
Expand Down
11 changes: 11 additions & 0 deletions src/services/date.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,15 @@ export class DateService {
public getDateLastDayInMonth(date: Date): Date {
return new Date(date.getFullYear(), date.getMonth() + 1, 0, 23, 59, 59, 59);
}

/**
*
* @param date
* @returns {boolean}
*/
public dateIsToday(date: Date): boolean {
const today = new Date();
return today.toDateString() == date.toDateString();
}

}
Loading

0 comments on commit 94f0084

Please sign in to comment.