diff --git a/src/app/constants.ts b/src/app/constants.ts
deleted file mode 100644
index 01bb4b7..0000000
--- a/src/app/constants.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export const GITHUB_USER = 'l10178';
-export const GITHUB_MARKDOWN_REPO = 'whisper';
-export const GITHUB_MARKDOWN_REPO_DEFAULT_BR = 'master';
diff --git a/src/app/detail/detail.page.ts b/src/app/detail/detail.page.ts
index 1a44b9f..25250a3 100644
--- a/src/app/detail/detail.page.ts
+++ b/src/app/detail/detail.page.ts
@@ -1,37 +1,18 @@
-import { Component, OnInit } from '@angular/core';
-import { ActivatedRoute } from '@angular/router';
-
-import {
- GITHUB_USER,
- GITHUB_MARKDOWN_REPO,
- GITHUB_MARKDOWN_REPO_DEFAULT_BR
-} from './../constants';
+import {Component, OnInit} from '@angular/core';
+import {ActivatedRoute} from '@angular/router';
@Component({
- selector: 'app-detail',
- templateUrl: 'detail.page.html',
- styleUrls: ['detail.page.scss']
+ selector: 'app-detail',
+ templateUrl: 'detail.page.html',
+ styleUrls: ['detail.page.scss']
})
export class DetailPage implements OnInit {
- public path: string;
- public id: string;
- constructor(private route: ActivatedRoute) {}
+ public path: string;
+ public id: string;
- ngOnInit() {
- const user = GITHUB_USER;
- const repo = GITHUB_MARKDOWN_REPO;
- const branch = GITHUB_MARKDOWN_REPO_DEFAULT_BR;
- this.route.params.subscribe(params => {
- let id = params.id;
- this.id = id;
- this.path = `https://raw.githubusercontent.com/${user}/${repo}/${branch}/${id}`;
- });
+ constructor(private route: ActivatedRoute) {
+ }
- // let github = new GitHub();
- // let repo = github.getRepo('l10178', 'little-jelly-bean-pieces');
- // let filePath = 'README.md';
- // repo.getContents('master', filePath, true).then(response => {
- // this.content = response.data;
- // });
- }
+ ngOnInit() {
+ }
}
diff --git a/src/app/edit/edit.page.html b/src/app/edit/edit.page.html
index 68f26b7..5eb0c65 100644
--- a/src/app/edit/edit.page.html
+++ b/src/app/edit/edit.page.html
@@ -1,22 +1,59 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/src/app/edit/edit.page.ts b/src/app/edit/edit.page.ts
index 8628586..1b3a976 100644
--- a/src/app/edit/edit.page.ts
+++ b/src/app/edit/edit.page.ts
@@ -1,128 +1,55 @@
-import { AccountService } from './../shared/account/account.service';
-import { BeanPiece } from './../shared/bean-piece.model';
-import { Component, OnInit } from '@angular/core';
-import { ToastController } from '@ionic/angular';
-import { Storage } from '@ionic/storage';
-import { ModalController } from '@ionic/angular';
+import {BeanPiece} from './../shared/bean-piece.model';
+import {Component, OnInit} from '@angular/core';
+import {ModalController, ToastController} from '@ionic/angular';
+import {Storage} from '@ionic/storage';
-import { Router, ActivatedRoute } from '@angular/router';
-
-import {
- GITHUB_USER,
- GITHUB_MARKDOWN_REPO,
- GITHUB_MARKDOWN_REPO_DEFAULT_BR
-} from './../constants';
-import GitHub from 'github-api';
-import { LoginPage } from '../login/login.page';
+import {ActivatedRoute, Router} from '@angular/router';
@Component({
- selector: 'app-edit',
- templateUrl: 'edit.page.html',
- styleUrls: ['edit.page.scss']
+ selector: 'app-edit',
+ templateUrl: 'edit.page.html',
+ styleUrls: ['edit.page.scss']
})
export class EditPage implements OnInit {
- public beanPiece: BeanPiece;
- constructor(
- private route: ActivatedRoute,
- private router: Router,
- private toastController: ToastController,
- private storage: Storage,
- private accountService: AccountService,
- public modalController: ModalController
- ) {}
-
- ngOnInit() {
- this.initContent();
- // check use login, if not, show login dialog
- this.checkLogin();
- }
-
- private initContent() {
- this.beanPiece = new BeanPiece();
- this.route.params.subscribe(params => {
- let fileId = params.id;
- if (fileId) {
- // TODO: redo
- this.beanPiece.title = fileId;
- let github = new GitHub();
- let repo = github.getRepo(GITHUB_USER, GITHUB_MARKDOWN_REPO);
- repo
- .getContents(GITHUB_MARKDOWN_REPO_DEFAULT_BR, fileId, true)
- .then(response => {
- this.beanPiece.description = response.data;
- });
- }
- });
- }
+ public beanPiece: BeanPiece;
+
+ constructor(
+ private route: ActivatedRoute,
+ private router: Router,
+ private toastController: ToastController,
+ private storage: Storage,
+ public modalController: ModalController
+ ) {
+ }
- async checkLogin() {
- const loginUser = await this.accountService.getLoginUser();
- if (loginUser === null) {
- // show login dialog
- this.showLoginModal();
+ ngOnInit() {
+ this.beanPiece = new BeanPiece();
}
- }
- async showLoginModal() {
- const modal = await this.modalController.create({
- component: LoginPage
- });
- return await modal.present();
- }
- autoSave() {
- // auto save to local
- if (this.beanPiece.title) {
- this.storage.set(this.beanPiece.title, this.beanPiece);
+ autoSave() {
+ // auto save to local
+ if (this.beanPiece.title) {
+ this.storage.set(this.beanPiece.title, this.beanPiece);
+ }
}
- }
- async save() {
- const loginUser = await this.accountService.getLoginUser();
- if (loginUser === null) {
- // show login dialog
- this.showLoginModal();
+ async save() {
+ this.doSuccess();
}
- let github = new GitHub(loginUser);
- let repo = github.getRepo(GITHUB_USER, GITHUB_MARKDOWN_REPO);
- const result = repo.writeFile(
- GITHUB_MARKDOWN_REPO_DEFAULT_BR,
- this.beanPiece.title + '.md',
- this.beanPiece.description,
- 'auto push by my app.',
- {
- encode: true
- }
- );
- result
- .then(data => {
- this.doSuccess(data);
- })
- .catch(error => {
- this.doError(error);
- });
- }
- private doError(error: any) {
- this.toast(error.message, 'danger');
- if (error.response.status === 401) {
- this.showLoginModal();
+ private doSuccess() {
+ this.toast('Success.', 'success');
+ this.router.navigate(['/list']);
}
- }
-
- private doSuccess(data: any) {
- this.toast(data.statusText, 'success');
- this.storage.remove(this.beanPiece.title);
- this.router.navigate(['/list']);
- }
- async toast(message: string, color: string) {
- const toast = await this.toastController.create({
- message: message,
- position: 'top',
- color: color,
- duration: 2000
- });
- toast.present();
- }
+ async toast(message: string, color: string) {
+ const toast = await this.toastController.create({
+ message: message,
+ position: 'top',
+ color: color,
+ duration: 2000
+ });
+ toast.present();
+ }
}
diff --git a/src/app/shared/model/meal-tag.model.ts b/src/app/shared/model/meal-tag.model.ts
new file mode 100644
index 0000000..322845b
--- /dev/null
+++ b/src/app/shared/model/meal-tag.model.ts
@@ -0,0 +1,9 @@
+export class MealTag {
+ name: string;
+ alias: string;
+ start: Date;
+ end: Date;
+
+ constructor() {
+ }
+}
diff --git a/src/app/shared/security/security.service.ts b/src/app/shared/security/security.service.ts
index 5a5c65f..5497bec 100644
--- a/src/app/shared/security/security.service.ts
+++ b/src/app/shared/security/security.service.ts
@@ -1,36 +1,39 @@
-import { Injectable } from '@angular/core';
+import {Injectable} from '@angular/core';
import * as CryptoJS from 'crypto-js';
+import {Time} from '@angular/common';
+import {Data} from '@angular/router';
@Injectable()
export class SecurityService {
- constructor() {}
+ constructor() {
+ }
- public encrypt(data: Object): string {
- if (data === null) {
- return null;
+ public encrypt(data: Object): string {
+ if (data === null) {
+ return null;
+ }
+ // // Encrypt
+ const ciphertext = CryptoJS.AES.encrypt(
+ JSON.stringify(data),
+ this.getSecurityKey()
+ );
+ return ciphertext.toString();
}
- // // Encrypt
- const ciphertext = CryptoJS.AES.encrypt(
- JSON.stringify(data),
- this.getSecurityKey()
- );
- return ciphertext.toString();
- }
- public decrypt(ciphertext: Object): any {
- if (ciphertext === null) {
- return null;
+ public decrypt(ciphertext: Object): any {
+ if (ciphertext === null) {
+ return null;
+ }
+ // // Decrypt
+ const bytes = CryptoJS.AES.decrypt(
+ ciphertext.toString(),
+ this.getSecurityKey()
+ );
+ const decryptedData = JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
+ return decryptedData;
}
- // // Decrypt
- var bytes = CryptoJS.AES.decrypt(
- ciphertext.toString(),
- this.getSecurityKey()
- );
- var decryptedData = JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
- return decryptedData;
- }
- getSecurityKey(): string {
- return 'this is just a test key.';
- }
+ getSecurityKey(): string {
+ return 'this is just a test key.';
+ }
}