Commit 1d10647c authored by h3remi7's avatar h3remi7

use new data struct

parent e4378b8c
<h1>{{name()}}</h1> <h1>{{name}}</h1>
<div *ngIf="!isInstalled()"> <div *ngIf="!isInstalled">
<button type="button" class="btn btn-primary">安装</button> <button type="button" class="btn btn-primary">安装</button>
<button type="button" class="btn btn-secondary">导入</button> <button type="button" class="btn btn-secondary">导入</button>
<button type="button" class="btn btn-secondary">正版代购</button> <button type="button" class="btn btn-secondary">正版代购</button>
</div> </div>
<div *ngIf="isInstalled()"> <div *ngIf="isInstalled">
<button type="button" class="btn btn-primary">运行</button> <button type="button" class="btn btn-primary">运行</button>
<button type="button" class="btn btn-secondary">设置</button> <button type="button" class="btn btn-secondary">设置</button>
<button type="button" class="btn btn-secondary">游览本地文件</button> <button type="button" class="btn btn-secondary">游览本地文件</button>
......
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { AppsService } from './apps.service' import { AppsService } from './apps.service'
import { RoutingService } from './routing.service' import { RoutingService } from './routing.service'
//import 'rxjs/Rx';
import {App} from "./app";
@Component({ @Component({
selector: 'app-detail', selector: 'app-detail',
templateUrl: 'app/app-detail.component.html', templateUrl: 'app/app-detail.component.html',
styleUrls: ['app/app-detail.component.css'], styleUrls: ['app/app-detail.component.css'],
}) })
export class AppDetailComponent { export class AppDetailComponent {
name() {
if(this.appsService.detail[this.routingService.app]) _currentApp;
{ get currentApp(): App {
return this.appsService.detail[this.routingService.app].name;
let data = this.appsService.data;
let tmp;
if(data) {
tmp = data.find((v)=>v.id === this.routingService.app);
return tmp;
} else { } else {
return this.appsService.detail["default"].name;
} }
}
_name;
get name() {
if(this.currentApp) {
return this.currentApp.name[this.currentApp.locales[0]];
}
return "Loading";
}; };
isInstalled() { _isInstalled;
if(this.appsService.detail[this.routingService.app]) get isInstalled() {
{ if(this.currentApp) {
return this.appsService.detail[this.routingService.app].isInstalled; if(this.currentApp.local.path) {
} else { return true;
return this.appsService.detail["default"].isInstalled;
} }
} }
return false;
}
constructor(private appsService: AppsService, private routingService: RoutingService ) { constructor(private appsService: AppsService, private routingService: RoutingService ) {
} }
......
...@@ -28,8 +28,26 @@ export class App { ...@@ -28,8 +28,26 @@ export class App {
tags: string[]; tags: string[];
version: string; version: string;
local: AppLocal; local: AppLocal;
constructor(app: AppInterface) {
this.id = app.id;
this.name = app.name;
this.description = app.description;
this.author = app.author;
this.homepage = app.homepage;
this.category = app.category;
this.actions = app.actions;
this.references = app.references;
this.locales = app.locales;
this.download = app.download;
this.news = app.news;
this.tags = app.tags;
this.version = app.version;
this.local = app.local;
}
} }
export interface AppInterface extends App {
}
/*export interface TestInterface { /*export interface TestInterface {
id: string; id: string;
name: {[locale: string]: string}; name: {[locale: string]: string};
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
class="list-group-item list-group-item-action" class="list-group-item list-group-item-action"
[ngClass]="{active: app.id==routingService.app}" [ngClass]="{active: app.id==routingService.app}"
> >
{{app.name}} {{app.name[app.locales[0]]}}
</a> </a>
<a href="#" class="list-group-item list-group-item-action disabled">{{routingService.app}}</a> <a href="#" class="list-group-item list-group-item-action disabled">{{routingService.app}}</a>
</div> </div>
\ No newline at end of file
...@@ -14,22 +14,14 @@ export class AppsComponent { ...@@ -14,22 +14,14 @@ export class AppsComponent {
console.log(appsService.data) console.log(appsService.data)
if(appsService.data.length > 0) { if(appsService.data.length > 0) {
this.selectApp(appsService.data[0].id); this.selectApp(appsService.data[0].id);
let tmp = this.appsService.data.filter((v)=>v.id === this.routingService.app);
console.log(tmp);
} }
}); });
} }
selectApp(id) { selectApp(id) {
this.routingService.app = id; this.routingService.app = id;
this.getDetail();
} }
getDetail() {
for(let i = 0; i < this.appsService.data.length; i++){
let x = this.appsService.data[i];
if(x.id == this.routingService.app) {
this.appsService.detail[this.routingService.app] = x;
}
}
console.log(this.appsService.detail);
}
} }
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {Http} from '@angular/http'; import {Http} from '@angular/http';
import 'rxjs/Rx'; import 'rxjs/Rx';
import {App} from "./app";
import {AppLocal} from "./app-local";
@Injectable() @Injectable()
export class AppsService { export class AppsService {
data; data : App[];
detail = {
"default": {
"id": "id",
"name": "name",
"isInstalled": false
},
}
constructor(private http: Http) { constructor(private http: Http) {
} }
getApps(callback) { getApps(callback) {
this.http.get('./apps.json') this.http.get('./apps.json')
.map(response => response.json()) .map(response => {
return response.json()
})
.subscribe(data => { .subscribe(data => {
this.data = data this.data = data;
console.log(this.data);
if(typeof(callback) === 'function') { if(typeof(callback) === 'function') {
callback(); callback();
} }
}); });
} }
} }
[ [
{ {
"id": "th105", "id": "th105",
"name": "东方绯想天", "name":
"isInstalled": true {
"zh-CN": "东方绯想天"
},
"description": {
"zh-CN": "fxt desc"
},
"author": "ZUN",
"homepage": "http://www.myacg.cc",
"category": "ACT",
"actions": {
"darwin": {
"main": {
"execute": "",
"args": [],
"env": "",
"open": ""
}
}
},
"references": {
"id": "",
"type": "runtime"
},
"locales": ["zh-CN"],
"download": "",
"news": [{
"title": "title",
"url": "",
"image": ""
}
],
"tags": ["ACT"],
"local": {
"path": "",
"version": ""
}
}, },
{ {
"id": "th12", "id": "th12",
"name": "东方地灵殿", "name":
"isInstalled": false
},
{ {
"id": "th13", "zh-CN": "地灵殿"
"name": "东方UFO", },
"isInstalled": false "description": {
"zh-CN": "th12 desc"
},
"author": "ZUN",
"homepage": "http://www.myacg.cc",
"category": "ACT",
"actions": {
"darwin": {
"main": {
"execute": "",
"args": [],
"env": "",
"open": ""
}
}
},
"references": {
"id": "",
"type": "runtime"
},
"locales": ["zh-CN"],
"download": "",
"news": [{
"title": "title",
"url": "",
"image": ""
}
],
"tags": ["ACT"],
"local": {
"path": "/foo/bar",
"version": "10.3"
}
} }
] ]
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment