Skip to content

Commit 1bfb45a

Browse files
committed
service upload file
1 parent b6f8c0b commit 1bfb45a

34 files changed

+521
-41
lines changed

.angulardoc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"repoId": "8767eec1-4c6c-4993-9853-097553c30c2e"
3+
}

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
<artifactId>spring-boot-starter-test</artifactId>
5454
<scope>test</scope>
5555
</dependency>
56+
<dependency>
57+
<groupId>org.springframework.boot</groupId>
58+
<artifactId>spring-boot-configuration-processor</artifactId>
59+
<optional>true</optional>
60+
</dependency>
5661
</dependencies>
5762

5863
<build>

src/angular/package-lock.json

Lines changed: 17 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/angular/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
"awesome-bootstrap-checkbox": "^1.0.1",
3434
"bootstrap": "^4.1.1",
3535
"core-js": "^2.5.6",
36-
"ngrx-data": "^6.0.0-beta.6",
37-
"ngx-toastr": "^8.7.3",
36+
"ngrx-data": "^6.0.2-beta.9",
37+
"ngx-spinner": "^6.0.0",
38+
"ngx-toastr": "^8.8.0",
3839
"rxjs": "^6.2.0",
3940
"rxjs-compat": "^6.1.0",
4041
"zone.js": "^0.8.19"
@@ -45,6 +46,7 @@
4546
"@angular/compiler-cli": "^6.0.3",
4647
"@angular/language-service": "^6.0.3",
4748
"@compodoc/compodoc": "^1.1.3",
49+
"@ngrx/schematics": "^6.0.1",
4850
"@types/jasmine": "^2.8.7",
4951
"@types/jasminewd2": "~2.0.3",
5052
"@types/node": "^6.0.109",

src/angular/src/app/admin/admin.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ <h6 class="mb-0 text-white lh-100">Admin</h6>
77
<small>All the stuff you want</small>
88
</div>
99
</div>
10+
11+
<app-upload></app-upload>
12+
1013
</main>

src/angular/src/app/admin/admin.module.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import { AdminRoutingModule } from './admin-routing.module';
44
import { AdminComponent } from './admin.component';
5+
import { UploadComponent } from './upload/upload.component';
6+
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
57

68
@NgModule({
7-
imports: [CommonModule, AdminRoutingModule],
8-
declarations: [AdminComponent]
9+
imports: [CommonModule, AdminRoutingModule, FormsModule, ReactiveFormsModule],
10+
declarations: [AdminComponent, UploadComponent]
911
})
1012
export class AdminModule {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<form [formGroup]="uploadForm" novalidate (submit)="submitFile()">
2+
3+
<div class="input-group mb-3">
4+
<div class="custom-file">
5+
<input type="file" class="custom-file-input" formControlName="fileUpload" #tmpFile (change)="onFileChange($event.target.files)">
6+
<label class="custom-file-label" for="file">{{tmpFile.value != '' ? tmpFile.value : 'Choose file'}}</label>
7+
</div>
8+
</div>
9+
<button type="submit" class="btn btn-primary" value="Upload">
10+
<i class="fas fa-upload"></i> Submit
11+
</button>
12+
13+
</form>

src/angular/src/app/admin/upload/upload.component.scss

Whitespace-only changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { UploadComponent } from './upload.component';
4+
5+
describe('UploadComponent', () => {
6+
let component: UploadComponent;
7+
let fixture: ComponentFixture<UploadComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ UploadComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(UploadComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
2+
import { FormControl, FormGroup, Validators } from '@angular/forms';
3+
import { FilesService } from '../../services/files.service';
4+
import {ToastrService} from "ngx-toastr";
5+
6+
@Component({
7+
selector: 'app-upload',
8+
templateUrl: './upload.component.html',
9+
styleUrls: ['./upload.component.scss']
10+
})
11+
export class UploadComponent implements OnInit {
12+
fileToUpload: File = null;
13+
uploadForm: FormGroup;
14+
15+
constructor(
16+
private cd: ChangeDetectorRef,
17+
private filesService: FilesService,
18+
private toastrservice: ToastrService
19+
) {}
20+
21+
ngOnInit() {
22+
this.uploadForm = new FormGroup({
23+
fileUpload: new FormControl('', Validators.required)
24+
});
25+
}
26+
27+
onFileChange(files: FileList) {
28+
this.fileToUpload = files.item(0);
29+
}
30+
31+
submitFile() {
32+
this.filesService.postFile(this.fileToUpload).subscribe((flag: any) => {
33+
console.log(flag);
34+
}, (error) => {
35+
this.toastrservice.error(error.error, 'Error with file upload');
36+
});
37+
}
38+
}

0 commit comments

Comments
 (0)