Commit 00440da2 authored by h3remi7's avatar h3remi7

add download (todo hide model)

parent c8512fac
...@@ -7,7 +7,10 @@ ...@@ -7,7 +7,10 @@
<button type="button" class="btn btn-secondary">正版代购</button> <button type="button" class="btn btn-secondary">正版代购</button>
</div> </div>
<div *ngIf="appsService.getDownloadInfo(routingService.app)"> <div *ngIf="appsService.getDownloadInfo(routingService.app)">
<progress *ngIf="appsService.getDownloadInfo(routingService.app).status === 'active'" class="progress progress-striped progress-animated" value="{{appsService.getDownloadInfo(mod.id).progress}}" max="100"></progress> <progress *ngIf="appsService.getDownloadInfo(routingService.app).status === 'active'"
class="progress progress-striped progress-animated"
value="{{appsService.getDownloadInfo(routingService.app).progress}}" max="100">
</progress>
</div> </div>
</div> </div>
<div *ngIf="isInstalled"> <div *ngIf="isInstalled">
...@@ -73,13 +76,14 @@ ...@@ -73,13 +76,14 @@
<!== DEBUG --> <!== DEBUG -->
<pre class="debug"> <pre class="debug">
{{appsService.downloadsInfo | json}} {{appsService.downloadsInfo | json}}
{{appsService.installConfig | json}}
</pre> </pre>
<!-- Modal --> <!-- Modal -->
<div class="modal fade" id="install-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" <div class="modal fade" id="install-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true"> aria-hidden="true">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<form class="modal-content" (ngSubmit)="install()"> <form class="modal-content" (ngSubmit)="installSubmit(theForm)" #theForm="ngForm">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
...@@ -92,7 +96,7 @@ ...@@ -92,7 +96,7 @@
<h4>安装位置</h4> <h4>安装位置</h4>
<div class="form-group"> <div class="form-group">
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control" placeholder="安装位置"> <input type="text" [(ngModel)]="appsService.installConfig.installDir" name="installDir" class="form-control" placeholder="安装位置">
<span class="input-group-btn"> <span class="input-group-btn">
<button class="btn btn-secondary" type="button">浏览</button> <button class="btn btn-secondary" type="button">浏览</button>
</span> </span>
...@@ -101,20 +105,20 @@ ...@@ -101,20 +105,20 @@
<h4>快捷方式</h4> <h4>快捷方式</h4>
<div class="checkbox"> <div class="checkbox">
<label> <label>
<input type="checkbox" (ngModel)="shortcut.application"> <input type="checkbox" [(ngModel)]="appsService.installConfig.shortcut.application" name="application">
创建应用程序快捷方式 创建应用程序快捷方式
</label> </label>
</div> </div>
<div class="checkbox"> <div class="checkbox">
<label> <label>
<input type="checkbox" (ngModel)="shortcut.desktop"> <input type="checkbox" [(ngModel)]="appsService.installConfig.shortcut.desktop" name="desktop">
创建桌面快捷方式 创建桌面快捷方式
</label> </label>
</div> </div>
<h4>附加内容</h4> <h4>附加内容</h4>
<div *ngFor="let mod of currentApp.references[platform]"> <div *ngFor="let mod of currentApp.references[platform]">
<label> <label>
<input type="checkbox" [(ngModel)]="model" name="{{mod.id}}" <input type="checkbox" [(ngModel)]="appsService.installConfig.mods[mod.id]" name="{{mod.id}}"
[disabled]="['dependency', 'runtime'].includes(mod.type)"> [disabled]="['dependency', 'runtime'].includes(mod.type)">
{{searchApp(mod.id).name[searchApp(mod.id).locales[0]]}} {{searchApp(mod.id).name[searchApp(mod.id).locales[0]]}}
</label> </label>
...@@ -122,9 +126,10 @@ ...@@ -122,9 +126,10 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button> <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<button type="button" class="btn btn-primary">安装</button> <button type="submit" [disabled]="!theForm.form.valid" class="btn btn-primary">安装</button>
</div> </div>
<pre>{{model}}</pre> <!--
-->
</form> </form>
</div> </div>
</div> </div>
...@@ -108,11 +108,26 @@ export class AppDetailComponent { ...@@ -108,11 +108,26 @@ export class AppDetailComponent {
let uri = this.searchApp(id).download; let uri = this.searchApp(id).download;
if(uri) { if(uri) {
this.appsService.download(id, uri); this.appsService.download(id, uri);
} else {
console.log("lost download uri!");
} }
}
} installSubmit(theForm) {
console.log(theForm);
this.install(this.routingService.app);
for(let mod in this.appsService.installConfig.mods) {
if(this.appsService.installConfig.mods[mod]) {
this.install(mod);
}
}
model; //TODO tar file
}
} }
...@@ -39,6 +39,9 @@ export class AppsComponent { ...@@ -39,6 +39,9 @@ export class AppsComponent {
selectApp(id) { selectApp(id) {
this.routingService.app = id; this.routingService.app = id;
this.appsService.createInstllConfig(id);
} }
} }
...@@ -5,13 +5,15 @@ import {App} from "./app"; ...@@ -5,13 +5,15 @@ import {App} from "./app";
import {AppLocal} from "./app-local"; import {AppLocal} from "./app-local";
import {TranslateService} from "ng2-translate"; import {TranslateService} from "ng2-translate";
declare var process;
@Injectable() @Injectable()
export class AppsService { export class AppsService {
constructor(private http: Http, private translate: TranslateService) { constructor(private http: Http, private translate: TranslateService) {
let loop = setInterval(()=> { let loop = setInterval(()=> {
this.aria2.tellActive().then((res)=> { this.aria2.tellActive().then((res)=> {
console.log('res:', res); //console.log('res:', res);
if(res) { if(res) {
res.map((v)=>{ res.map((v)=>{
let index = this.downloadsInfo.findIndex((info)=>{ let index = this.downloadsInfo.findIndex((info)=>{
...@@ -75,8 +77,8 @@ export class AppsService { ...@@ -75,8 +77,8 @@ export class AppsService {
}); });
}; };
this._aria2.onmessage = (m)=> { this._aria2.onmessage = (m)=> {
console.log('IN:', m); //console.log('IN:', m);
console.log('download infoi:', this.downloadsInfo); //console.log('download infoi:', this.downloadsInfo);
} }
} }
...@@ -136,11 +138,11 @@ export class AppsService { ...@@ -136,11 +138,11 @@ export class AppsService {
} }
download(id, uri) { download(id, uri) {
console.log(id); //console.log(id);
console.log(uri); //console.log(uri);
let tmp_gid; let tmp_gid;
let i = this.downloadsInfo.findIndex((v)=>{return v.id == id}); let i = this.downloadsInfo.findIndex((v)=>{return v.id == id});
console.log(i); //console.log(i);
if(this.downloadsInfo.findIndex((v)=>{return v.id == id}) !== -1) { if(this.downloadsInfo.findIndex((v)=>{return v.id == id}) !== -1) {
console.log("this app downloading") console.log("this app downloading")
...@@ -149,7 +151,7 @@ export class AppsService { ...@@ -149,7 +151,7 @@ export class AppsService {
if (error) { if (error) {
console.error(error); console.error(error);
} }
console.log(gid); //console.log(gid);
this.downloadsInfo.push({"id": id, "gid": gid, "status": "active", "progress": 0}); this.downloadsInfo.push({"id": id, "gid": gid, "status": "active", "progress": 0});
}); });
} }
...@@ -165,7 +167,33 @@ export class AppsService { ...@@ -165,7 +167,33 @@ export class AppsService {
}); });
return info; return info;
}
installConfig;
createInstllConfig(id) {
let app = this.data.find((app)=>{return app.id == id;});
let platform = process.platform;
let mods = {};
if(app.references[platform]) {
app.references[platform].map((mod)=>{
mods[mod.id] = false;
});
}
let tmp = {
installDir: __dirname,
shortcut: {
desktop: false,
application: false
},
mods: mods
};
//console.log(tmp);
this.installConfig = tmp;
return tmp;
} }
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
"references": { "references": {
"darwin": [ "darwin": [
{ {
"id": "th105", "id": "th06",
"type": "optional" "type": "optional"
}, },
{ {
...@@ -135,13 +135,13 @@ ...@@ -135,13 +135,13 @@
"locales": [ "locales": [
"zh-CN" "zh-CN"
], ],
"download": "", "download": "http://thief.mycard.moe/metalinks/th12.meta4",
"news": [], "news": [],
"tags": [ "tags": [
"STG" "STG"
], ],
"local": { "local": {
"path": "/foo/bar", "path": "",
"version": "10.3" "version": "10.3"
} }
}, },
...@@ -170,7 +170,7 @@ ...@@ -170,7 +170,7 @@
"locales": [ "locales": [
"zh-CN" "zh-CN"
], ],
"download": "", "download": "http://thief.mycard.moe/metalinks/th11.meta4",
"news": [], "news": [],
"tags": [ "tags": [
"STG" "STG"
...@@ -205,7 +205,7 @@ ...@@ -205,7 +205,7 @@
"locales": [ "locales": [
"zh-CN" "zh-CN"
], ],
"download": "", "download": "http://thief.mycard.moe/metalinks/th10.meta4",
"news": [ "news": [
{ {
"title": "News Title", "title": "News Title",
......
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