Commit feaaa807 authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

add groups in Boilerplates(ui needs update)

parent e3083e2d
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
...@@ -9,6 +9,8 @@ import { SignupComponent } from './components/singup/singup.component'; ...@@ -9,6 +9,8 @@ import { SignupComponent } from './components/singup/singup.component';
import { BoilerplateListComponent } from './components/boilerplate-list/boilerplate-list.component'; import { BoilerplateListComponent } from './components/boilerplate-list/boilerplate-list.component';
import { BoilerplateDetailsComponent } from './components/boilerplate-details/boilerplate-details.component'; import { BoilerplateDetailsComponent } from './components/boilerplate-details/boilerplate-details.component';
import { AddBoilerplateComponent } from './components/add-boilerplate/add-boilerplate.component'; import { AddBoilerplateComponent } from './components/add-boilerplate/add-boilerplate.component';
import { GroupboilComponent } from './components/groupboil/groupboil.component';
import { AddGroupboilComponent } from './components/add-groupboil/add-groupboil.component';
/*import { PrefixListComponent } from './components/prefix-list/prefix-list.component'; /*import { PrefixListComponent } from './components/prefix-list/prefix-list.component';
import { PrefixDetailsComponent } from './components/prefix-details/prefix-details.component'; import { PrefixDetailsComponent } from './components/prefix-details/prefix-details.component';
...@@ -18,9 +20,11 @@ const routes: Routes = [ ...@@ -18,9 +20,11 @@ const routes: Routes = [
{ path: '', redirectTo: 'login', pathMatch: 'full' }, { path: '', redirectTo: 'login', pathMatch: 'full' },
{ path: 'login', component: LoginComponent }, { path: 'login', component: LoginComponent },
{ path: 'signup', component: SignupComponent }, { path: 'signup', component: SignupComponent },
{ path: 'boilerplates', component: BoilerplateListComponent, canActivate: [AuthGuard] }, { path: 'groupboilerplates', component: GroupboilComponent, canActivate: [AuthGuard] },
{ path: 'boilerplates/:id', component: BoilerplateDetailsComponent, canActivate: [AuthGuard] }, { path: 'groupboilerplates/:gb/boilerplates', component: BoilerplateListComponent, canActivate: [AuthGuard] },
{ path: 'add-boilerplate', component: AddBoilerplateComponent, canActivate: [AuthGuard] } { path: 'groupboilerplates/:gb/boilerplates/:id', component: BoilerplateDetailsComponent, canActivate: [AuthGuard] },
{ path: 'groupboilerplates/:gb/boilerplates/add-boilerplate', component: AddBoilerplateComponent, canActivate: [AuthGuard] },
{ path: 'add-groupboil', component: AddGroupboilComponent, canActivate: [AuthGuard] }
/*{ path: '', redirectTo: 'tutorials', pathMatch: 'full' }, /*{ path: '', redirectTo: 'tutorials', pathMatch: 'full' },
{ path: 'prefix', component: PrefixListComponent }, { path: 'prefix', component: PrefixListComponent },
{ path: 'prefix/:id', component: PrefixDetailsComponent }, { path: 'prefix/:id', component: PrefixDetailsComponent },
......
...@@ -30,6 +30,8 @@ import { MainListComponent } from './components/main-list/main-list.component'; ...@@ -30,6 +30,8 @@ import { MainListComponent } from './components/main-list/main-list.component';
import { MainDetailsComponent } from './components/main-details/main-details.component'; import { MainDetailsComponent } from './components/main-details/main-details.component';
import { SuffixListComponent } from './components/suffix-list/suffix-list.component'; import { SuffixListComponent } from './components/suffix-list/suffix-list.component';
import { SuffixDetailsComponent } from './components/suffix-details/suffix-details.component'; import { SuffixDetailsComponent } from './components/suffix-details/suffix-details.component';
import { GroupboilComponent } from './components/groupboil/groupboil.component';
import { AddGroupboilComponent } from './components/add-groupboil/add-groupboil.component';
...@@ -50,6 +52,8 @@ import { SuffixDetailsComponent } from './components/suffix-details/suffix-detai ...@@ -50,6 +52,8 @@ import { SuffixDetailsComponent } from './components/suffix-details/suffix-detai
MainDetailsComponent, MainDetailsComponent,
SuffixListComponent, SuffixListComponent,
SuffixDetailsComponent, SuffixDetailsComponent,
GroupboilComponent,
AddGroupboilComponent,
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
......
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {Router} from '@angular/router'; import {ActivatedRoute, Router} from '@angular/router';
import { Boilerplate } from 'src/app/models/boilerplate.model'; import { Boilerplate } from 'src/app/models/boilerplate.model';
import { BoilerplateService } from 'src/app/services/boilerplate.service'; import { BoilerplateService } from 'src/app/services/boilerplate.service';
import { NotifierService } from "angular-notifier"; import { NotifierService } from "angular-notifier";
@Component({ @Component({
selector: 'app-add-boilerplate', selector: 'app-add-boilerplate',
templateUrl: './add-boilerplate.component.html', templateUrl: './add-boilerplate.component.html',
...@@ -11,6 +12,7 @@ import { NotifierService } from "angular-notifier"; ...@@ -11,6 +12,7 @@ import { NotifierService } from "angular-notifier";
}) })
export class AddBoilerplateComponent implements OnInit { export class AddBoilerplateComponent implements OnInit {
boilerplate: Boilerplate = { boilerplate: Boilerplate = {
group_of_boilerplate: this.route.snapshot.params.gb,
title: "", title: "",
has_prefix: false, has_prefix: false,
has_main: false, has_main: false,
...@@ -19,7 +21,8 @@ export class AddBoilerplateComponent implements OnInit { ...@@ -19,7 +21,8 @@ export class AddBoilerplateComponent implements OnInit {
submitted = false; submitted = false;
private readonly notifier: NotifierService; private readonly notifier: NotifierService;
constructor(private boilerplatelService: BoilerplateService, private router:Router, notifierService: NotifierService) { constructor(private boilerplatelService: BoilerplateService, private route: ActivatedRoute,
private router: Router, notifierService: NotifierService) {
this.notifier = notifierService; this.notifier = notifierService;
} }
...@@ -28,18 +31,19 @@ export class AddBoilerplateComponent implements OnInit { ...@@ -28,18 +31,19 @@ export class AddBoilerplateComponent implements OnInit {
saveBoilerplate(): void { saveBoilerplate(): void {
const data = { const data = {
group_of_boilerplate: this.route.snapshot.params.gb,
title: this.boilerplate.title, title: this.boilerplate.title,
has_prefix: this.boilerplate.has_prefix, has_prefix: this.boilerplate.has_prefix,
has_main: this.boilerplate.has_main, has_main: this.boilerplate.has_main,
has_suffix: this.boilerplate.has_suffix has_suffix: this.boilerplate.has_suffix
}; };
this.boilerplatelService.create(data) this.boilerplatelService.create(this.route.snapshot.params.gb, data)
.subscribe( .subscribe(
response => { response => {
this.notifier.notify("success",(JSON.stringify(response))); this.notifier.notify("success",(JSON.stringify(response)));
this.submitted = true; this.submitted = true;
this.router.navigate(['/boilerplates']); this.router.navigate(['/groupboilerplates/'+this.route.snapshot.params.gb+'/boilerplates']);
}, },
error => { error => {
console.log(error); console.log(error);
...@@ -51,6 +55,7 @@ export class AddBoilerplateComponent implements OnInit { ...@@ -51,6 +55,7 @@ export class AddBoilerplateComponent implements OnInit {
newBoilerplate(): void { newBoilerplate(): void {
this.submitted = false; this.submitted = false;
this.boilerplate = { this.boilerplate = {
group_of_boilerplate: this.route.snapshot.params.gb,
title: "", title: "",
has_prefix: false, has_prefix: false,
has_main: false, has_main: false,
......
<div>
<div class="submit-form">
<div class="form-group">
<label for="title">Requirement Title</label>
<input
type="text"
class="form-control"
id="title_bgroup"
required
[(ngModel)]="groupboilerplate.title_bgroup"
name="title_bgroup"
/>
<button (click)="saveBoilerplate()" class="btn btn-success" >Submit</button>
</div>
</div>
\ No newline at end of file
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AddGroupboilComponent } from './add-groupboil.component';
describe('AddGroupboilComponent', () => {
let component: AddGroupboilComponent;
let fixture: ComponentFixture<AddGroupboilComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ AddGroupboilComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(AddGroupboilComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
import {Router} from '@angular/router';
import { GroupBoilerplate } from 'src/app/models/boilerplate.model';
import { BoilerplateService } from 'src/app/services/boilerplate.service';
import { NotifierService } from "angular-notifier";
@Component({
selector: 'app-add-groupboil',
templateUrl: './add-groupboil.component.html',
styleUrls: ['./add-groupboil.component.scss']
})
export class AddGroupboilComponent implements OnInit {
groupboilerplate: GroupBoilerplate = {
title_bgroup: "",
};
submitted = false;
private readonly notifier: NotifierService;
constructor(private boilerplatelService: BoilerplateService, private router:Router, notifierService: NotifierService) {
this.notifier = notifierService;
}
ngOnInit(): void {
}
saveBoilerplate(): void {
const data = {
title_bgroup: this.groupboilerplate.title_bgroup,
};
this.boilerplatelService.creategroupboil(data)
.subscribe(
response => {
this.notifier.notify("success",(JSON.stringify(response)));
this.submitted = true;
this.router.navigate(['/groupboilerplates']);
},
error => {
console.log(error);
//error, warning, success, info, default
this.notifier.notify("warning",(JSON.stringify(error["error"]["title"][0])));
});
}
newBoilerplate(): void {
this.submitted = false;
this.groupboilerplate = {
title_bgroup: "",
};
}
}
...@@ -27,11 +27,11 @@ export class BoilerplateDetailsComponent implements OnInit { ...@@ -27,11 +27,11 @@ export class BoilerplateDetailsComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.message = ''; this.message = '';
this.getBoilerplate(this.route.snapshot.params.id); this.getBoilerplate(this.route.snapshot.params.gb, this.route.snapshot.params.id);
} }
getBoilerplate(id: string): void { getBoilerplate(gb:any, id: number): void {
this.boilerplateService.get(id) this.boilerplateService.get(gb, id)
.subscribe( .subscribe(
data => { data => {
this.currentboilerplate = data; this.currentboilerplate = data;
...@@ -43,7 +43,7 @@ export class BoilerplateDetailsComponent implements OnInit { ...@@ -43,7 +43,7 @@ export class BoilerplateDetailsComponent implements OnInit {
} }
updateBoilerplate(): void { updateBoilerplate(): void {
this.boilerplateService.update(this.currentboilerplate.id, this.currentboilerplate) this.boilerplateService.update(this.route.snapshot.params.gb, this.currentboilerplate.id, this.currentboilerplate)
.subscribe( .subscribe(
response => { response => {
console.log(response); console.log(response);
...@@ -57,7 +57,7 @@ export class BoilerplateDetailsComponent implements OnInit { ...@@ -57,7 +57,7 @@ export class BoilerplateDetailsComponent implements OnInit {
deleteBoilerplate(): void { deleteBoilerplate(): void {
if(confirm("Αre you sure you want to delete this Boilerplate?")) { if(confirm("Αre you sure you want to delete this Boilerplate?")) {
this.boilerplateService.delete(this.currentboilerplate.id) this.boilerplateService.delete(this.route.snapshot.params.gb, this.currentboilerplate.id)
.subscribe( .subscribe(
response => { response => {
console.log(response); console.log(response);
......
<div>
<div>
<input type="button" value="Add Boilepate" (click)="GetRoute()"/>
</div>
</div>
<div class="list row"> <div class="list row">
<div class="col-md-8"> <div class="col-md-8">
<div class="input-group mb-3"> <div class="input-group mb-3">
...@@ -19,7 +25,7 @@ ...@@ -19,7 +25,7 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<table mat-table [dataSource]="newdataSource" class="mat-elevation-z8"> <table mat-table [dataSource]="newdataSource" class="mat-elevation-z8">
...@@ -54,7 +60,7 @@ ...@@ -54,7 +60,7 @@
<ng-container matColumnDef="action"> <ng-container matColumnDef="action">
<th mat-header-cell *matHeaderCellDef> Action </th> <th mat-header-cell *matHeaderCellDef> Action </th>
<td mat-cell *matCellDef="let element" class="action-link"> <td mat-cell *matCellDef="let element" class="action-link">
<a class="badge badge-warning" routerLink="/boilerplates/{{ element.id }}">Edit</a> <a class="badge badge-warning" routerLink="{{element.id}}">Edit</a>
</td> </td>
</ng-container> </ng-container>
......
...@@ -3,6 +3,7 @@ import { Boilerplate } from 'src/app/models/boilerplate.model'; ...@@ -3,6 +3,7 @@ import { Boilerplate } from 'src/app/models/boilerplate.model';
import { BoilerplateData } from 'src/app/models/boilerplate.model'; import { BoilerplateData } from 'src/app/models/boilerplate.model';
import { BoilerplateService } from 'src/app/services/boilerplate.service'; import { BoilerplateService } from 'src/app/services/boilerplate.service';
import { PrefixService } from 'src/app/services/prefix.service'; import { PrefixService } from 'src/app/services/prefix.service';
import { ActivatedRoute, Router } from '@angular/router';
...@@ -30,7 +31,8 @@ export class BoilerplateListComponent implements OnInit { ...@@ -30,7 +31,8 @@ export class BoilerplateListComponent implements OnInit {
main: any; main: any;
suffix: any; suffix: any;
constructor(private boilerplateService: BoilerplateService, private prefixService: PrefixService) { } constructor(private boilerplateService: BoilerplateService, private prefixService: PrefixService, private route: ActivatedRoute,
private router: Router) { }
ngOnInit(): void { ngOnInit(): void {
this.retrieveBoilerplates(); this.retrieveBoilerplates();
...@@ -38,7 +40,7 @@ export class BoilerplateListComponent implements OnInit { ...@@ -38,7 +40,7 @@ export class BoilerplateListComponent implements OnInit {
} }
retrieveBoilerplates(): void { retrieveBoilerplates(): void {
this.boilerplateService.getAll() this.boilerplateService.getAll(this.route.snapshot.params.gb)
.subscribe( .subscribe(
data => { data => {
this.boilerplates = data; this.boilerplates = data;
...@@ -52,7 +54,7 @@ export class BoilerplateListComponent implements OnInit { ...@@ -52,7 +54,7 @@ export class BoilerplateListComponent implements OnInit {
retrieve(): void { retrieve(): void {
this.boilerplateService.getAllData() this.boilerplateService.getAllData(this.route.snapshot.params.gb)
.subscribe( .subscribe(
data => { data => {
this.boilerplatesdata =data; this.boilerplatesdata =data;
...@@ -79,7 +81,7 @@ export class BoilerplateListComponent implements OnInit { ...@@ -79,7 +81,7 @@ export class BoilerplateListComponent implements OnInit {
SearchTitle(): void { SearchTitle(): void {
if (this.title != ''){ if (this.title != ''){
this.boilerplateService.findByTitle(this.title) this.boilerplateService.findByTitle(this.route.snapshot.params.gb, this.title)
.subscribe( .subscribe(
data => { data => {
this.boilerplates = data; this.boilerplates = data;
...@@ -95,5 +97,11 @@ export class BoilerplateListComponent implements OnInit { ...@@ -95,5 +97,11 @@ export class BoilerplateListComponent implements OnInit {
this.retrieveBoilerplates(); this.retrieveBoilerplates();
} }
} }
GetRoute(): void {
this.router.navigate(['/groupboilerplates/'+ this.route.snapshot.params.gb +'/boilerplates/add-boilerplate'])
}
GetRoutedit(id: any): void {
this.router.navigate(['/groupboilerplates/'+ this.route.snapshot.params.gb +'/boilerplates'+ id])
}
} }
<p>groupboil works!</p>
<div>
<a routerLink="/add-groupboil">Add Boilepate</a>
</div>
<li *ngFor="let gb of grouboilerplates">
<a class="badge badge-warning" routerLink="/groupboilerplates/{{gb.id}}/boilerplates">"{{gb.title_bgroup}}"</a>
<span class="badge">{{gb.id}}</span>
</li>
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { GroupboilComponent } from './groupboil.component';
describe('GroupboilComponent', () => {
let component: GroupboilComponent;
let fixture: ComponentFixture<GroupboilComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ GroupboilComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(GroupboilComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
import { GroupBoilerplate } from 'src/app/models/boilerplate.model';
import { BoilerplateService } from 'src/app/services/boilerplate.service';
@Component({
selector: 'app-groupboil',
templateUrl: './groupboil.component.html',
styleUrls: ['./groupboil.component.scss']
})
export class GroupboilComponent implements OnInit {
grouboilerplates?: GroupBoilerplate[];
constructor(private boilerplateService: BoilerplateService) { }
ngOnInit(): void {
this.retrievegroupBoilerplates();
}
retrievegroupBoilerplates(): void {
this.boilerplateService.getAllgroupboil()
.subscribe(
data => {console.log(data);
this.grouboilerplates = data;
},
error => {
console.log(error);
});
}
}
...@@ -35,7 +35,7 @@ export class LoginComponent implements OnInit { ...@@ -35,7 +35,7 @@ export class LoginComponent implements OnInit {
login(email: string, password: string) { login(email: string, password: string) {
this.authService.login(email, password).subscribe( this.authService.login(email, password).subscribe(
success => this.router.navigate(['boilerplates']), success => this.router.navigate(['groupboilerplates']),
error => this.notifier.notify("warning",(JSON.stringify("You have entered an invalid username or password"))) error => this.notifier.notify("warning",(JSON.stringify("You have entered an invalid username or password")))
); );
} }
......
export class Boilerplate { export class Boilerplate {
id?:any; id?:any;
group_of_boilerplate?: any;
title?: string; title?: string;
has_prefix?: boolean; has_prefix?: boolean;
has_main?: boolean; has_main?: boolean;
...@@ -13,3 +14,8 @@ export class BoilerplateData { ...@@ -13,3 +14,8 @@ export class BoilerplateData {
main_data?: string; main_data?: string;
suffix_data?: string; suffix_data?: string;
} }
export class GroupBoilerplate {
id?:any;
title_bgroup?: string;
}
\ No newline at end of file
...@@ -9,9 +9,6 @@ ...@@ -9,9 +9,6 @@
</div> </div>
<div fxFlex fxLayout fxHide.xs fxLayoutAlign="end"> <div fxFlex fxLayout fxHide.xs fxLayoutAlign="end">
<ul fxLayout fxLayoutGap="15px" class="navigation-items"> <ul fxLayout fxLayoutGap="15px" class="navigation-items">
<div>
<a routerLink="/add-boilerplate">Add Boilepate</a>
</div>
<div> <div>
<a mat-menu-item (click)="LogOut()">Log out</a> <a mat-menu-item (click)="LogOut()">Log out</a>
</div> </div>
......
...@@ -3,8 +3,10 @@ import { HttpClient } from '@angular/common/http'; ...@@ -3,8 +3,10 @@ import { HttpClient } from '@angular/common/http';
import { HttpHeaders } from '@angular/common/http'; import { HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { Boilerplate } from '../models/boilerplate.model'; import { Boilerplate } from '../models/boilerplate.model';
import { GroupBoilerplate } from '../models/boilerplate.model';
const baseUrl = 'http://155.207.131.19:8000/api-auth/boilerplates/'; const baseUrl = '/boilerplates/';
const baseUrlgb = 'http://155.207.131.19:8000/api-auth/groupboilerplates/';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
...@@ -13,32 +15,42 @@ export class BoilerplateService { ...@@ -13,32 +15,42 @@ export class BoilerplateService {
constructor(private http: HttpClient) { } constructor(private http: HttpClient) { }
getAll(): Observable<Boilerplate[]> { creategroupboil(data: any): Observable<any> {
return this.http.get<Boilerplate[]>(baseUrl); return this.http.post(baseUrlgb, data);
} }
getAllData(): Observable<Boilerplate[]> { getAllgroupboil(): Observable<Boilerplate[]> {
return this.http.get<Boilerplate[]>(baseUrl + `boilerplatedata/`); return this.http.get<[GroupBoilerplate]>(baseUrlgb);
} }
get(id: any): Observable<Boilerplate> { getAll(gb: any): Observable<Boilerplate[]> {
return this.http.get(`${baseUrl}${id}`); //console.log(baseUrlgb + gb + baseUrl)
return this.http.get<Boilerplate[]>(baseUrlgb + gb + baseUrl);
} }
create(data: any): Observable<any> { getAllData(gb: any): Observable<Boilerplate[]> {
return this.http.post(baseUrl, data); return this.http.get<Boilerplate[]>(baseUrlgb + gb + baseUrl+ `boilerplatedata/`);
} }
update(id: any, data: any): Observable<any> { get(gb: any, id: any): Observable<Boilerplate> {
return this.http.put(`${baseUrl}${id}/`, data); console.log(id)
return this.http.get(`${baseUrlgb}${gb}${baseUrl}${id}`);
} }
delete(id: any): Observable<any> { create(gb: any, data: any): Observable<any> {
return this.http.delete(`${baseUrl}${id}`); return this.http.post(baseUrlgb + gb + baseUrl, data);
} }
findByTitle(title: any): Observable<Boilerplate[]> { update(gb: any,id: any, data: any): Observable<any> {
return this.http.get<Boilerplate[]>(`${baseUrl}title=${title}`); return this.http.put(`${baseUrlgb}${gb}${baseUrl}${id}/`, data);
}
delete(gb: any, id: any): Observable<any> {
return this.http.delete(`${baseUrlgb}${gb}${baseUrl}${id}`);
}
findByTitle(gb: any, title: any): Observable<Boilerplate[]> {
return this.http.get<Boilerplate[]>(`${baseUrlgb}${gb}${baseUrl}title=${title}`);
} }
} }
...@@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http'; ...@@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { Main } from '../models/main.model'; import { Main } from '../models/main.model';
const baseUrl = 'http://155.207.131.19:8000/api-auth/boilerplates/'; const baseUrl = 'http://155.207.131.19:8000/api-auth/groupboilerplates/0/boilerplates/';
const Url = '/main/'; const Url = '/main/';
@Injectable({ @Injectable({
......
...@@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http'; ...@@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { Prefix } from '../models/prefix.model'; import { Prefix } from '../models/prefix.model';
const baseUrl = 'http://155.207.131.19:8000/api-auth/boilerplates/'; const baseUrl = 'http://155.207.131.19:8000/api-auth/groupboilerplates/0/boilerplates/';
const Url = '/prefix/'; const Url = '/prefix/';
@Injectable({ @Injectable({
......
...@@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http'; ...@@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { Suffix } from '../models/suffix.model'; import { Suffix } from '../models/suffix.model';
const baseUrl = 'http://155.207.131.19:8000/api-auth/boilerplates/'; const baseUrl = 'http://155.207.131.19:8000/api-auth/groupboilerplates/0/boilerplates/';
const Url = '/suffix/'; const Url = '/suffix/';
@Injectable({ @Injectable({
......
...@@ -55,17 +55,32 @@ def create_prefix(instance): ...@@ -55,17 +55,32 @@ def create_prefix(instance):
prefix = Prefix(prefix_boilerplate = instance.boilerplate, prefixgroup = instance) prefix = Prefix(prefix_boilerplate = instance.boilerplate, prefixgroup = instance)
prefix.save() prefix.save()
def create_data(instance): def create_data(instance):
data = BoilerplateData(boilerplate_data_id = instance, owner_data = instance.owner, title_data= instance.title) data = BoilerplateData(boilerplate_data_id = instance, owner_data = instance.owner, title_data= instance.title, group_of_boilerplate_data = instance.group_of_boilerplate )
data.save() data.save()
def create_extra_prefix(instance, now_prefix): def create_extra_prefix(instance, now_prefix):
prefix = Prefix(prefixgroup = instance.prefixgroup, prefix_boilerplate = instance.prefix_boilerplate) prefix = Prefix(prefixgroup = instance.prefixgroup, prefix_boilerplate = instance.prefix_boilerplate)
prefix.save() prefix.save()
def create_infer_result(instance):
pass
class BoilerplateGroup(models.Model):
boilerplate_owner = models.ForeignKey(User, related_name='boilerplate_group_owner', on_delete=models.CASCADE)
title_bgroup = models.CharField(max_length=30, unique=True)
def save(self, **kwargs):
super(BoilerplateGroup, self).save(**kwargs)
class Boilerplate(models.Model): class Boilerplate(models.Model):
owner = models.ForeignKey(User, related_name='boilerplate', on_delete=models.CASCADE) owner = models.ForeignKey(User, related_name='boilerplate', on_delete=models.CASCADE)
group_of_boilerplate = models.ForeignKey(BoilerplateGroup, related_name='owner_of_boilerplate', on_delete=models.CASCADE)
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
title = models.CharField(max_length=30, unique=True) title = models.CharField(max_length=30, unique=True)
has_prefix = models.BooleanField(default=False) has_prefix = models.BooleanField(default=False)
...@@ -163,6 +178,7 @@ class Prefix(models.Model): ...@@ -163,6 +178,7 @@ class Prefix(models.Model):
class BoilerplateData(models.Model): class BoilerplateData(models.Model):
owner_data = models.ForeignKey(User, related_name='boilerplate_data', on_delete=models.CASCADE) owner_data = models.ForeignKey(User, related_name='boilerplate_data', on_delete=models.CASCADE)
group_of_boilerplate_data = models.ForeignKey(BoilerplateGroup, related_name='group_of_boilerplate_data', on_delete=models.CASCADE)
boilerplate_data_id = models.ForeignKey(Boilerplate, related_name='boilerplate_data_id', on_delete=models.CASCADE) boilerplate_data_id = models.ForeignKey(Boilerplate, related_name='boilerplate_data_id', on_delete=models.CASCADE)
title_data = models.CharField(default="", max_length=30, unique=True) title_data = models.CharField(default="", max_length=30, unique=True)
prefix_data = models.CharField(default="", max_length=100, blank=True) prefix_data = models.CharField(default="", max_length=100, blank=True)
...@@ -171,3 +187,11 @@ class BoilerplateData(models.Model): ...@@ -171,3 +187,11 @@ class BoilerplateData(models.Model):
class Meta: class Meta:
ordering = ['boilerplate_data_id'] ordering = ['boilerplate_data_id']
#class InferenceResults(models.Model):
# owner_infer = models.ForeignKey(User, related_name='owner_infer', on_delete=models.CASCADE)
# inference_data = models.CharField(default="")
# class Meta:
# ordering = ['owner_infer']
from rest_framework import serializers from rest_framework import serializers
from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate, BoilerplateData from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate, BoilerplateData, BoilerplateGroup
class BoilerplateSerializer(serializers.ModelSerializer): class BoilerplateSerializer(serializers.ModelSerializer):
owner = serializers.ReadOnlyField(source='owner.username') owner = serializers.ReadOnlyField(source='owner.username')
class Meta: class Meta:
model = Boilerplate model = Boilerplate
fields = ('id', 'owner', 'title', 'has_prefix', 'has_main', 'has_suffix') fields = ('id', 'group_of_boilerplate', 'owner', 'title', 'has_prefix', 'has_main', 'has_suffix')
class PrefixSerializer(serializers.ModelSerializer): class PrefixSerializer(serializers.ModelSerializer):
...@@ -23,3 +23,10 @@ class BoilerplateDataSerializer(serializers.ModelSerializer): ...@@ -23,3 +23,10 @@ class BoilerplateDataSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = BoilerplateData model = BoilerplateData
fields = '__all__' fields = '__all__'
class BoilerplateGroupSerializer(serializers.ModelSerializer):
boilerplate_owner = serializers.ReadOnlyField(source='owner.username')
class Meta:
model = BoilerplateGroup
fields = ('id', 'boilerplate_owner', 'title_bgroup')
...@@ -7,21 +7,24 @@ from .views import user_views, requirements_views, main_req_views, suffix_req_vi ...@@ -7,21 +7,24 @@ from .views import user_views, requirements_views, main_req_views, suffix_req_vi
urlpatterns = [ urlpatterns = [
path('users/', user_views.UserList.as_view(), name='api-user-list'), path('users/', user_views.UserList.as_view(), name='api-user-list'),
path('users/<uuid:pk>/', user_views.UserDetail.as_view(), name='api-post-details'), path('users/<uuid:pk>/', user_views.UserDetail.as_view(), name='api-post-details'),
path('boilerplates/', requirements_views.BoilerplateListCreateAPIView.as_view(), name='api-requirements-list'), path('groupboilerplates/', requirements_views.BoilerplateGroupCreateAPIView.as_view(), name='api-groupboilerplates-create'),
path('boilerplates/<int:pk>/', requirements_views.BoilerplateDetailsAPIView.as_view(), name='api-requirements-details'), path('groupboilerplates/<int:pk>/', requirements_views.BoilerplateGroupList.as_view(), name='api-groupboilerplates-list'),
path('boilerplates/boilerplatedata/', requirements_views.BoilerplateDataListAPIView.as_view(), name='api-boilerlplate-list-data'),
re_path('boilerplates/(?:title=(?P<title_1>\w+)/)?$', requirements_views.BoilerplateList.as_view(), name='api-requirements-details-per-title'), path('groupboilerplates/<int:groupboil>/boilerplates/', requirements_views.BoilerplateListCreateAPIView.as_view(), name='api-requirements-list'),
path('groupboilerplates/<int:groupboil>/boilerplates/<int:pk>/', requirements_views.BoilerplateDetailsAPIView.as_view(), name='api-requirements-details'),
path('groupboilerplates/<int:groupboil>/boilerplates/boilerplatedata/', requirements_views.BoilerplateDataListAPIView.as_view(), name='api-boilerlplate-list-data'),
re_path('groupboilerplates/<int:groupboil>/boilerplates/(?:title=(?P<title_1>\w+)/)?$', requirements_views.BoilerplateList.as_view(), name='api-requirements-details-per-title'),
#'''Prefix''' #'''Prefix'''
path('boilerplates/<int:boilerplate>/prefix/', requirements_views.PrefixListAPIView.as_view(), name='api-prefix-list'), path('groupboilerplates/<int:groupboil>/boilerplates/<int:boilerplate>/prefix/', requirements_views.PrefixListAPIView.as_view(), name='api-prefix-list'),
path('boilerplates/<int:boilerplate>/prefix/<int:pk>/', requirements_views.PrefixDetailsAPIView.as_view(), name='api-prefix-details'), path('groupboilerplates/<int:groupboil>/boilerplates/<int:boilerplate>/prefix/<int:pk>/', requirements_views.PrefixDetailsAPIView.as_view(), name='api-prefix-details'),
#'''MAIN''' #'''MAIN'''
path('boilerplates/<int:boilerplate>/main/', main_req_views.MainListAPIView.as_view(), name='api-main-list'), path('groupboilerplates/<int:groupboil>/boilerplates/<int:boilerplate>/main/', main_req_views.MainListAPIView.as_view(), name='api-main-list'),
path('boilerplates/<int:boilerplate>/main/<int:pk>/', main_req_views.MainDetailsAPIView.as_view(), name='api-main-details'), path('groupboilerplates/<int:groupboil>/boilerplates/<int:boilerplate>/main/<int:pk>/', main_req_views.MainDetailsAPIView.as_view(), name='api-main-details'),
#'''SUFFIX''' #'''SUFFIX'''
path('boilerplates/<int:boilerplate>/suffix/', suffix_req_views.SuffixListAPIView.as_view(), name='api-suffix-list'), path('groupboilerplates/<int:groupboil>/boilerplates/<int:boilerplate>/suffix/', suffix_req_views.SuffixListAPIView.as_view(), name='api-suffix-list'),
path('boilerplates/<int:boilerplate>/suffix/<int:pk>/', suffix_req_views.SuffixDetailsAPIView.as_view(), name='api-suffix-details'), path('groupboilerplates/<int:groupboil>/boilerplates/<int:boilerplate>/suffix/<int:pk>/', suffix_req_views.SuffixDetailsAPIView.as_view(), name='api-suffix-details'),
#PREFIX CHOICES DATA #PREFIX CHOICES DATA
path('prefix/choices/simpleprefix/', requirements_views.PrefixChoicesViewSet.as_view(), name='simpleprefixchoices'), path('prefix/choices/simpleprefix/', requirements_views.PrefixChoicesViewSet.as_view(), name='simpleprefixchoices'),
......
...@@ -5,10 +5,10 @@ from django.http import HttpResponse, JsonResponse ...@@ -5,10 +5,10 @@ from django.http import HttpResponse, JsonResponse
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from rest_framework.parsers import JSONParser from rest_framework.parsers import JSONParser
from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate, PREFIX_CHOICES, LOGIC_CONNECTIVE, VERB_CHOICES from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate, BoilerplateGroup, PREFIX_CHOICES, LOGIC_CONNECTIVE, VERB_CHOICES
from reqman.apps.reqtool.models.requirements import VERB_CHOICES, ITEM_CHOICES, SYSTEM_CHOICES, FUNCTION_CHOICES, STATE_CHOICES from reqman.apps.reqtool.models.requirements import VERB_CHOICES, ITEM_CHOICES, SYSTEM_CHOICES, FUNCTION_CHOICES, STATE_CHOICES
from reqman.apps.reqtool.models.requirements import ITEM_CHOICES, FLOW_CHOICES, FUNCTION_CHOICES, STATE_VALUE_CHOICES from reqman.apps.reqtool.models.requirements import ITEM_CHOICES, FLOW_CHOICES, FUNCTION_CHOICES, STATE_VALUE_CHOICES
from reqman.apps.reqtool.rest_api.serializers.requirements import BoilerplateSerializer, PrefixSerializer, BoilerplateDataSerializer from reqman.apps.reqtool.rest_api.serializers.requirements import BoilerplateSerializer, PrefixSerializer, BoilerplateDataSerializer, BoilerplateGroupSerializer
from reqman.apps.permissions import IsOwnerOrReadOnly from reqman.apps.permissions import IsOwnerOrReadOnly
from reqman.apps.reqtool.rest_api.services import fuseki from reqman.apps.reqtool.rest_api.services import fuseki
from rest_framework.response import Response from rest_framework.response import Response
...@@ -17,6 +17,36 @@ from rest_framework.views import APIView ...@@ -17,6 +17,36 @@ from rest_framework.views import APIView
from reqman.apps.reqtool.models.requirements import BoilerplateData from reqman.apps.reqtool.models.requirements import BoilerplateData
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
##
class BoilerplateGroupCreateAPIView(ListCreateAPIView):
"""
API view to retrieve list of posts or create new
"""
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
serializer_class = BoilerplateGroupSerializer
def get_queryset(self):
queryset_boil = BoilerplateGroup.objects.filter(boilerplate_owner = self.request.user)
return queryset_boil
#Custom actions when POST
def perform_create(self, serializer):
serializer.save(boilerplate_owner=self.request.user)
class BoilerplateGroupList(ListAPIView):
"""
API view to retrieve list of posts based on title of Boilerplate
"""
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
serializer_class = BoilerplateGroupSerializer
queryset = Boilerplate.objects.all()
###
class BoilerplateListCreateAPIView(ListCreateAPIView): class BoilerplateListCreateAPIView(ListCreateAPIView):
""" """
API view to retrieve list of posts or create new API view to retrieve list of posts or create new
...@@ -27,7 +57,8 @@ class BoilerplateListCreateAPIView(ListCreateAPIView): ...@@ -27,7 +57,8 @@ class BoilerplateListCreateAPIView(ListCreateAPIView):
def get_queryset(self): def get_queryset(self):
#print(title) #print(title)
queryset_boil = Boilerplate.objects.filter(owner = self.request.user) group_gb = self.kwargs['groupboil']
queryset_boil = Boilerplate.objects.filter(owner = self.request.user, group_of_boilerplate = group_gb)
return queryset_boil return queryset_boil
#Custom actions when POST #Custom actions when POST
...@@ -43,13 +74,14 @@ class BoilerplateList(ListAPIView): ...@@ -43,13 +74,14 @@ class BoilerplateList(ListAPIView):
""" """
permission_classes = [permissions.IsAuthenticatedOrReadOnly] permission_classes = [permissions.IsAuthenticatedOrReadOnly]
serializer_class = BoilerplateSerializer serializer_class = BoilerplateSerializer
queryset = Boilerplate.objects.all() #queryset = Boilerplate.objects.all()
def get_queryset(self): def get_queryset(self):
group_gb = self.kwargs['groupboil']
title = self.kwargs['title_1'] title = self.kwargs['title_1']
#print(title) #print(title)
queryset_title = Boilerplate.objects.filter(title = title) queryset_title = Boilerplate.objects.filter(title = title, group_of_boilerplate = group_gb)
return queryset_title return queryset_title
...@@ -133,6 +165,7 @@ class PrefixDetailsAPIView(RetrieveUpdateDestroyAPIView): ...@@ -133,6 +165,7 @@ class PrefixDetailsAPIView(RetrieveUpdateDestroyAPIView):
instance.delete() instance.delete()
class BoilerplateDataListAPIView(ListAPIView): class BoilerplateDataListAPIView(ListAPIView):
""" """
API view to retrieve list of posts or create new API view to retrieve list of posts or create new
...@@ -142,8 +175,8 @@ class BoilerplateDataListAPIView(ListAPIView): ...@@ -142,8 +175,8 @@ class BoilerplateDataListAPIView(ListAPIView):
#queryset = Prefix.objects.all() #queryset = Prefix.objects.all()
def get_queryset(self): def get_queryset(self):
#print(title) group_gb = self.kwargs['groupboil']
queryset_boil_data = BoilerplateData.objects.filter(owner_data = self.request.user) queryset_boil_data = BoilerplateData.objects.filter(owner_data = self.request.user, group_of_boilerplate_data = group_gb)
return queryset_boil_data return queryset_boil_data
......
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