Commit c9fd6f23 authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

add (unique) title for Boilerplate

parent 7f58fd01
<div> <div>
<div class="submit-form"> <div class="submit-form">
<div *ngIf="!submitted"> <div *ngIf="!submitted">
<div class="form-group">
<label for="title">Requirement Title</label>
<input
type="text"
class="form-control"
id="title"
required
[(ngModel)]="boilerplate.title"
name="title"
/>
</div>
<div class="form-group"> <div class="form-group">
<label for="has_prefix">Prefix</label> <label for="has_prefix">Prefix</label>
<input <input
...@@ -39,7 +50,6 @@ ...@@ -39,7 +50,6 @@
<button (click)="saveBoilerplate()" class="btn btn-success">Submit</button> <button (click)="saveBoilerplate()" class="btn btn-success">Submit</button>
</div> </div>
<div *ngIf="submitted"> <div *ngIf="submitted">
<h4>Tutorial was submitted successfully!</h4> <h4>Tutorial was submitted successfully!</h4>
<button class="btn btn-success" (click)="newBoilerplate()">Add</button> <button class="btn btn-success" (click)="newBoilerplate()">Add</button>
......
...@@ -9,6 +9,7 @@ import { BoilerplateService } from 'src/app/services/boilerplate.service'; ...@@ -9,6 +9,7 @@ import { BoilerplateService } from 'src/app/services/boilerplate.service';
}) })
export class AddBoilerplateComponent implements OnInit { export class AddBoilerplateComponent implements OnInit {
boilerplate: Boilerplate = { boilerplate: Boilerplate = {
title: "",
has_prefix: false, has_prefix: false,
has_main: false, has_main: false,
has_suffix: false has_suffix: false
...@@ -22,6 +23,7 @@ export class AddBoilerplateComponent implements OnInit { ...@@ -22,6 +23,7 @@ export class AddBoilerplateComponent implements OnInit {
saveBoilerplate(): void { saveBoilerplate(): void {
const data = { const data = {
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
...@@ -41,6 +43,7 @@ export class AddBoilerplateComponent implements OnInit { ...@@ -41,6 +43,7 @@ export class AddBoilerplateComponent implements OnInit {
newBoilerplate(): void { newBoilerplate(): void {
this.submitted = false; this.submitted = false;
this.boilerplate = { this.boilerplate = {
title: "",
has_prefix: false, has_prefix: false,
has_main: false, has_main: false,
has_suffix: false has_suffix: false
......
...@@ -8,18 +8,18 @@ ...@@ -8,18 +8,18 @@
[(ngModel)]="boilerplates" [(ngModel)]="boilerplates"
/> />
<div class="input-group-append"> <div class="input-group-append">
<!-- <button <button
class="btn btn-outline-secondary" class="btn btn-outline-secondary"
type="button" type="button"
(click)="" (click)="SearchTitle()"
> >
Search Search
</button> --> </button>
</div> </div>
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<h4>Boilerplate List</h4> <h4>Tutorials List</h4>
<ul class="list-group"> <ul class="list-group">
<li <li
class="list-group-item" class="list-group-item"
...@@ -27,14 +27,16 @@ ...@@ -27,14 +27,16 @@
[class.active]="i == currentIndex" [class.active]="i == currentIndex"
(click)="setActiveBoilerplate(boilerplate, i)" (click)="setActiveBoilerplate(boilerplate, i)"
> >
{{boilerplate.title }}
</li> </li>
</ul> </ul>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<div *ngIf="currentBoilerplate"> <div *ngIf="currentBoilerplate">
<h4>Boilerplate</h4> <h4>Boilerplate</h4>
<div>
<label><strong>Title:</strong></label> {{ currentBoilerplate.title }}
</div>
<div> <div>
<label><strong>Prefix:</strong></label> <label><strong>Prefix:</strong></label>
{{ currentBoilerplate.has_prefix }} {{ currentBoilerplate.has_prefix }}
......
...@@ -12,7 +12,7 @@ export class BoilerplateListComponent implements OnInit { ...@@ -12,7 +12,7 @@ export class BoilerplateListComponent implements OnInit {
boilerplates?: Boilerplate[]; boilerplates?: Boilerplate[];
currentBoilerplate?: Boilerplate; currentBoilerplate?: Boilerplate;
currentIndex = -1; currentIndex = -1;
//title = ''; title = '';
constructor(private boilerplateService: BoilerplateService) { } constructor(private boilerplateService: BoilerplateService) { }
...@@ -43,4 +43,17 @@ export class BoilerplateListComponent implements OnInit { ...@@ -43,4 +43,17 @@ export class BoilerplateListComponent implements OnInit {
this.currentIndex = index; this.currentIndex = index;
} }
SearchTitle(): void {
this.boilerplateService.findByTitle(this.title)
.subscribe(
data => {
this.boilerplates = data;
console.log(data);
},
error => {
console.log(error);
});
}
} }
export class Boilerplate { export class Boilerplate {
id?:any; id?:any;
title?: string;
has_prefix?: boolean; has_prefix?: boolean;
has_main?: boolean; has_main?: boolean;
has_suffix?: boolean; has_suffix?: boolean;
......
...@@ -33,8 +33,8 @@ export class BoilerplateService { ...@@ -33,8 +33,8 @@ export class BoilerplateService {
} }
//In case we want to find by something //In case we want to find by something
/*findByTitle(title: any): Observable<Boilerplate[]> { findByTitle(title: any): Observable<Boilerplate[]> {
return this.http.get<Boilerplate[]>(`${baseUrl}?title=${title}`); return this.http.get<Boilerplate[]>(`${baseUrl}?title=${title}`);
}*/ }
} }
...@@ -64,6 +64,7 @@ def create_extra_prefix(instance, now_prefix): ...@@ -64,6 +64,7 @@ def create_extra_prefix(instance, now_prefix):
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)
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
title = models.CharField(max_length=30, unique=True)
has_prefix = models.BooleanField(default=False) has_prefix = models.BooleanField(default=False)
has_main = models.BooleanField(default=False) has_main = models.BooleanField(default=False)
has_suffix = models.BooleanField(default=False) has_suffix = models.BooleanField(default=False)
......
...@@ -5,7 +5,7 @@ class BoilerplateSerializer(serializers.ModelSerializer): ...@@ -5,7 +5,7 @@ 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', 'has_prefix', 'has_main', 'has_suffix') fields = ('id', 'owner', 'title', 'has_prefix', 'has_main', 'has_suffix')
class PrefixSerializer(serializers.ModelSerializer): class PrefixSerializer(serializers.ModelSerializer):
......
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