[general] Add import and export data

This commit is contained in:
samnyan
2020-04-01 00:51:37 +09:00
parent a0bdd4121f
commit cfca166ac9
18 changed files with 259 additions and 11 deletions

View File

@@ -32,7 +32,10 @@ export class ApiService {
}
getHost(): string {
return this.authenticationService.currentUserValue.apiServer + '/';
if (this.authenticationService.currentUserValue) {
return this.authenticationService.currentUserValue.apiServer + '/';
}
return 'http://localhost:80' + '/';
}
show() {

View File

@@ -4,12 +4,14 @@ import {LoginComponent} from './login/login.component';
import {DashboardComponent} from './dashboard/dashboard.component';
import {AuthGuardService} from './auth/auth-guard.service';
import {ChangelogComponent} from './changelog/changelog.component';
import {ImporterComponent} from './importer/importer/importer.component';
const routes: Routes = [
{path: '', redirectTo: '/login', pathMatch: 'full'},
{path: 'login', component: LoginComponent},
{path: 'dashboard', component: DashboardComponent, canActivate: [AuthGuardService]},
{path: 'changelog', component: ChangelogComponent},
{path: 'import', component: ImporterComponent},
{path: 'diva', loadChildren: () => import('./sega/diva/diva.module').then(mod => mod.DivaModule), canLoad: [AuthGuardService]},
{path: 'ongeki', loadChildren: () => import('./sega/ongeki/ongeki.module').then(mod => mod.OngekiModule), canLoad: [AuthGuardService]},
{

View File

@@ -21,6 +21,7 @@
fixedTopGap="56">
<mat-nav-list>
<a mat-list-item routerLink="/dashboard">Dashboard</a>
<a mat-list-item routerLink="/import">Import</a>
<!-- <a mat-list-item routerLink="/changelog">Changelog</a>-->
<mat-divider></mat-divider>
<mat-toolbar>O.N.G.E.K.I</mat-toolbar>

View File

@@ -27,6 +27,7 @@ import {OngekiModule} from './sega/ongeki/ongeki.module';
import {ErrorInterceptorService} from './auth/error-interceptor.service';
import {LoadingInterceptorService} from './auth/loading-interceptor.service';
import {ChangelogComponent} from './changelog/changelog.component';
import {ImporterModule} from './importer/importer.module';
@NgModule({
declarations: [
@@ -45,6 +46,7 @@ import {ChangelogComponent} from './changelog/changelog.component';
AppRoutingModule,
DashboardModule,
LoginModule,
ImporterModule,
DivaModule,
AmazonModule,
OngekiModule,

View File

@@ -0,0 +1,22 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {ImporterComponent} from './importer/importer.component';
import {MatCardModule} from '@angular/material/card';
import {MatButtonModule} from '@angular/material/button';
import {MatInputModule} from '@angular/material/input';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
@NgModule({
declarations: [ImporterComponent],
imports: [
CommonModule,
MatButtonModule,
MatInputModule,
MatCardModule,
ReactiveFormsModule,
FormsModule,
]
})
export class ImporterModule {
}

View File

@@ -0,0 +1,23 @@
.upload-button::-webkit-file-upload-button {
visibility: hidden;
}
.upload-button::before {
content: 'Select File';
cursor: pointer;
outline: none;
border: none;
-webkit-tap-highlight-color: transparent;
display: inline-block;
white-space: nowrap;
text-decoration: none;
vertical-align: baseline;
text-align: center;
margin: 0;
min-width: 64px;
line-height: 36px;
padding: 0 16px;
border-radius: 4px;
overflow: visible;
background-color: #595959;
}

View File

@@ -0,0 +1,30 @@
<mat-card>
<mat-card-title>
Import Data
</mat-card-title>
<mat-card-content>
<mat-form-field class="example-full-width">
<mat-label>API Server</mat-label>
<input [(ngModel)]="apiServer" matInput placeholder="">
</mat-form-field>
</mat-card-content>
</mat-card>
<mat-card>
<mat-card-title>
CHUNITHM
</mat-card-title>
<mat-card-content>
<input (change)="chunithm($event)" accept=".json" class="upload-button" type='file'>
</mat-card-content>
</mat-card>
<mat-card>
<mat-card-title>
ONGEKI
</mat-card-title>
<mat-card-content>
<input (change)="ongeki($event)" accept=".json" class="upload-button" type='file'>
</mat-card-content>
</mat-card>

View File

@@ -0,0 +1,25 @@
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {ImporterComponent} from './importer.component';
describe('ImporterComponent', () => {
let component: ImporterComponent;
let fixture: ComponentFixture<ImporterComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ImporterComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ImporterComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,55 @@
import {Component, OnInit} from '@angular/core';
import {MessageService} from '../../message.service';
import {HttpClient} from '@angular/common/http';
import {AuthenticationService} from '../../auth/authentication.service';
@Component({
selector: 'app-importer',
templateUrl: './importer.component.html',
styleUrls: ['./importer.component.css']
})
export class ImporterComponent implements OnInit {
apiServer: string;
constructor(
private http: HttpClient,
private messageService: MessageService,
private authenticationService: AuthenticationService
) {
}
ngOnInit(): void {
if (this.authenticationService.currentUserValue) {
this.apiServer = this.authenticationService.currentUserValue.apiServer;
} else {
this.apiServer = 'http://localhost:80';
}
}
chunithm(event) {
this.uploadDocument(event.target.files[0], 'api/game/chuni/amazon/import', 'SDBT');
}
ongeki(event) {
this.uploadDocument(event.target.files[0], 'api/game/ongeki/import', 'SDDT');
}
uploadDocument(file: File, path: string, type: string) {
const fileReader = new FileReader();
fileReader.onload = (e) => {
const j = JSON.parse(fileReader.result.toString());
console.log(j);
if (j.gameId === type) {
this.http.post(this.apiServer + '/' + path, j).subscribe(
data => this.messageService.notice('OK'),
error => this.messageService.notice(error)
);
} else {
this.messageService.notice('Wrong Game ID, please check you have select the correct file.');
}
};
fileReader.readAsText(file);
this.messageService.notice('Uploading...');
}
}

View File

@@ -8,10 +8,7 @@ import {LoginComponent} from './login.component';
import {AppRoutingModule} from '../app-routing.module';
import {LayoutModule} from '@angular/cdk/layout';
import {DashboardModule} from '../dashboard/dashboard.module';
import {ContainerModule} from '../container/container.module';
import {RegisterModule} from '../register/register.module';
import {HttpClientModule} from '@angular/common/http';
import {PlayerboardListModule} from '../playerboard-list/playerboard-list.module';
describe('LoginComponent', () => {
let component: LoginComponent;
@@ -27,13 +24,10 @@ describe('LoginComponent', () => {
HttpClientModule,
DashboardModule,
ContainerModule,
RegisterModule,
ReactiveFormsModule,
MatButtonModule,
MatInputModule,
MatCardModule,
PlayerboardListModule
]
}).compileComponents();
}));

View File

@@ -22,3 +22,11 @@
</mat-card-content>
</mat-card>
<mat-card>
<mat-card-title>Export data</mat-card-title>
<mat-card-content>
<div class="action">
<a href="{{apiServer + '/api/game/chuni/amazon/export?aimeId=' + aimeId}}" mat-button target="_blank">Download</a>
</div>
</mat-card-content>
</mat-card>

View File

@@ -16,6 +16,7 @@ export class AmazonSettingComponent implements OnInit {
profile: AmazonProfile;
aimeId: string;
apiServer: string;
constructor(
private api: ApiService,
@@ -25,15 +26,15 @@ export class AmazonSettingComponent implements OnInit {
) { }
ngOnInit() {
const aimeId = String(this.auth.currentUserValue.extId);
const param = new HttpParams().set('aimeId', aimeId);
this.aimeId = String(this.auth.currentUserValue.extId);
this.apiServer = this.auth.currentUserValue.apiServer;
const param = new HttpParams().set('aimeId', this.aimeId);
this.api.get('api/game/chuni/amazon/profile', param).subscribe(
data => {
this.profile = data;
},
error => this.messageService.notice(error)
);
this.aimeId = String(this.auth.currentUserValue.extId);
}
userName() {

View File

@@ -0,0 +1,12 @@
<mat-card>
<mat-card-title>ONGEKI Settings</mat-card-title>
</mat-card>
<mat-card>
<mat-card-title>Export data</mat-card-title>
<mat-card-content>
<div class="action">
<a href="{{apiServer + '/api/game/ongeki/export?aimeId=' + aimeId}}" mat-button target="_blank">Download</a>
</div>
</mat-card-content>
</mat-card>

View File

@@ -0,0 +1,25 @@
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {OngekiSettingComponent} from './ongeki-setting.component';
describe('OngekiSettingComponent', () => {
let component: OngekiSettingComponent;
let fixture: ComponentFixture<OngekiSettingComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [OngekiSettingComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(OngekiSettingComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,41 @@
import {Component, OnInit} from '@angular/core';
import {ApiService} from '../../../api.service';
import {AuthenticationService} from '../../../auth/authentication.service';
import {MessageService} from '../../../message.service';
import {MatDialog} from '@angular/material/dialog';
import {HttpParams} from '@angular/common/http';
import {DisplayOngekiProfile} from '../model/OngekiProfile';
@Component({
selector: 'app-ongeki-setting',
templateUrl: './ongeki-setting.component.html',
styleUrls: ['./ongeki-setting.component.css']
})
export class OngekiSettingComponent implements OnInit {
profile: DisplayOngekiProfile;
aimeId: string;
apiServer: string;
constructor(
private api: ApiService,
private auth: AuthenticationService,
private messageService: MessageService,
public dialog: MatDialog
) {
}
ngOnInit(): void {
this.aimeId = String(this.auth.currentUserValue.extId);
this.apiServer = this.auth.currentUserValue.apiServer;
const param = new HttpParams().set('aimeId', this.aimeId);
this.api.get('api/game/ongeki/profile', param).subscribe(
data => {
this.profile = data;
},
error => this.messageService.notice(error)
);
}
}

View File

@@ -23,6 +23,7 @@ import {ToLevelDecimalPipe} from './util/to-level-decimal.pipe';
import {ToBattleSpritePipe} from './util/to-battle-sprite.pipe';
import {ToTechSpritePipe} from './util/to-tech-sprite.pipe';
import {OngekiCardGachaComponent} from './ongeki-card-gacha/ongeki-card-gacha.component';
import {OngekiSettingComponent} from './ongeki-setting/ongeki-setting.component';
@NgModule({
@@ -38,7 +39,8 @@ import {OngekiCardGachaComponent} from './ongeki-card-gacha/ongeki-card-gacha.co
ToLevelDecimalPipe,
ToBattleSpritePipe,
ToTechSpritePipe,
OngekiCardGachaComponent
OngekiCardGachaComponent,
OngekiSettingComponent
],
imports: [
CommonModule,

View File

@@ -7,6 +7,7 @@ import {OngekiSongListComponent} from './ongeki-song-list/ongeki-song-list.compo
import {OngekiBattlePointComponent} from './ongeki-battle-point/ongeki-battle-point.component';
import {OngekiRatingComponent} from './ongeki-rating/ongeki-rating.component';
import {OngekiCardGachaComponent} from './ongeki-card-gacha/ongeki-card-gacha.component';
import {OngekiSettingComponent} from './ongeki-setting/ongeki-setting.component';
const routes: Routes = [
@@ -18,6 +19,7 @@ const routes: Routes = [
{path: 'card', component: OngekiCardComponent},
{path: 'card/all', component: OngekiCardListComponent},
{path: 'card/gacha', component: OngekiCardGachaComponent},
{path: 'setting', component: OngekiSettingComponent},
];
export const OngekiRoutes = RouterModule.forChild(routes);