Commit c9fd6f23 authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

add (unique) title for Boilerplate

parent 7f58fd01
<div>
<div class="submit-form">
<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">
<label for="has_prefix">Prefix</label>
<input
......@@ -39,7 +50,6 @@
<button (click)="saveBoilerplate()" class="btn btn-success">Submit</button>
</div>
<div *ngIf="submitted">
<h4>Tutorial was submitted successfully!</h4>
<button class="btn btn-success" (click)="newBoilerplate()">Add</button>
......
......@@ -9,6 +9,7 @@ import { BoilerplateService } from 'src/app/services/boilerplate.service';
})
export class AddBoilerplateComponent implements OnInit {
boilerplate: Boilerplate = {
title: "",
has_prefix: false,
has_main: false,
has_suffix: false
......@@ -22,6 +23,7 @@ export class AddBoilerplateComponent implements OnInit {
saveBoilerplate(): void {
const data = {
title: this.boilerplate.title,
has_prefix: this.boilerplate.has_prefix,
has_main: this.boilerplate.has_main,
has_suffix: this.boilerplate.has_suffix
......@@ -41,6 +43,7 @@ export class AddBoilerplateComponent implements OnInit {
newBoilerplate(): void {
this.submitted = false;
this.boilerplate = {
title: "",
has_prefix: false,
has_main: false,
has_suffix: false
......
......@@ -8,18 +8,18 @@
[(ngModel)]="boilerplates"
/>
<div class="input-group-append">
<!-- <button
<button
class="btn btn-outline-secondary"
type="button"
(click)=""
(click)="SearchTitle()"
>
Search
</button> -->
</button>
</div>
</div>
</div>
<div class="col-md-6">
<h4>Boilerplate List</h4>
<h4>Tutorials List</h4>
<ul class="list-group">
<li
class="list-group-item"
......@@ -27,14 +27,16 @@
[class.active]="i == currentIndex"
(click)="setActiveBoilerplate(boilerplate, i)"
>
{{boilerplate.title }}
</li>
</ul>
</div>
<div class="col-md-6">
<div *ngIf="currentBoilerplate">
<h4>Boilerplate</h4>
<div>
<label><strong>Title:</strong></label> {{ currentBoilerplate.title }}
</div>
<div>
<label><strong>Prefix:</strong></label>
{{ currentBoilerplate.has_prefix }}
......
......@@ -12,7 +12,7 @@ export class BoilerplateListComponent implements OnInit {
boilerplates?: Boilerplate[];
currentBoilerplate?: Boilerplate;
currentIndex = -1;
//title = '';
title = '';
constructor(private boilerplateService: BoilerplateService) { }
......@@ -43,4 +43,17 @@ export class BoilerplateListComponent implements OnInit {
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 {
id?:any;
title?: string;
has_prefix?: boolean;
has_main?: boolean;
has_suffix?: boolean;
......
......@@ -33,8 +33,8 @@ export class BoilerplateService {
}
//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}`);
}*/
}
}
......@@ -64,6 +64,7 @@ def create_extra_prefix(instance, now_prefix):
class Boilerplate(models.Model):
owner = models.ForeignKey(User, related_name='boilerplate', on_delete=models.CASCADE)
created = models.DateTimeField(auto_now_add=True)
title = models.CharField(max_length=30, unique=True)
has_prefix = models.BooleanField(default=False)
has_main = models.BooleanField(default=False)
has_suffix = models.BooleanField(default=False)
......
......@@ -5,7 +5,7 @@ class BoilerplateSerializer(serializers.ModelSerializer):
owner = serializers.ReadOnlyField(source='owner.username')
class Meta:
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):
......
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