Commit 4f220ffb authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

get choices in angular

parent 147a1854
......@@ -57,7 +57,10 @@
</button>
<p>{{ message }}</p>
</div>
<!---->
<app-prefix-details></app-prefix-details>
<app-prefix-list></app-prefix-list>
<!---->
<div *ngIf="!currentboilerplate.id">
<br />
<p>Cannot access this Boilerplate...</p>
......
......@@ -32,7 +32,7 @@ export class BoilerplateDetailsComponent implements OnInit {
.subscribe(
data => {
this.currentboilerplate = data;
console.log(data);
//console.log(data);
},
error => {
console.log(error);
......
......@@ -19,46 +19,6 @@
</div>
</div>
</div>
<!--
<div class="col-md-6">
<h4>Boilerplate List</h4>
<ul class="list-group">
<li
class="list-group-item"
*ngFor="let boilerplate of boilerplates; let i = index"
[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 }}
</div>
<div>
<label><strong>Main:</strong></label>
{{ currentBoilerplate.has_main }}
</div>
<div>
<label><strong>Suffix:</strong></label>
{{ currentBoilerplate.has_suffix }}
</div>
<a class="badge badge-warning" routerLink="/boilerplates/{{ currentBoilerplate.id }}">
Edit
</a>
</div>
</div>
<div>
<button class="btn btn-success" routerLink="/add-boilerplate">Add</button>
</div>-->
</div>
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
......
<p>prefix-details works!</p>
<ng-container *ngFor= "let prefix of simpleprefix">
<ul>
<li>{{prefix[1]}}</li>
</ul>
\ No newline at end of file
import { Component, OnInit } from '@angular/core';
import { Prefix } from 'src/app/models/prefix.model';
import { PrefixService } from 'src/app/services/prefix.service';
@Component({
selector: 'app-prefix-details',
templateUrl: './prefix-details.component.html',
styleUrls: ['./prefix-details.component.scss']
})
export class PrefixDetailsComponent implements OnInit {
constructor() { }
//for the moment only one prefix can showed/updates
currentprefix: Prefix = {
prefix: "",
system_fun_item: "",
state_or_verb: "",
item_function_flow_statevalue: "",
logical_expression: "",
logic_connective: "",
simple_prefix: "",
};
message = '';
simpleprefix = [];
subjects = [];
verbs = [];
objects = [];
logic_con = [];
ngOnInit(): void {
constructor(
private prefixService: PrefixService) { }
ngOnInit(): void { this.getchoices();
}
getPrefix(boilerplate: any, id: string): void {
this.prefixService.get(boilerplate, id)
.subscribe(
data => {
this.currentprefix = data;
console.log(data);
},
error => {
console.log(error);
});
}
getchoices(): void{
this.prefixService.getsimpleprefix()
.subscribe(
data => {
this.simpleprefix = data;
},
error => {
console.log(error);
});
this.prefixService.getlogcon()
.subscribe(
data => {
this.logic_con = data;
},
error => {
console.log(error);
});
this.prefixService.getverb()
.subscribe(
data => {
this.verbs = data;
},
error => {
console.log(error);
});
this.prefixService.getsubject()
.subscribe(
data => {
this.subjects = data;
},
error => {
console.log(error);
});
this.prefixService.getoobject()
.subscribe(
data => {
this.objects = data;
},
error => {
console.log(error);
});
}
}
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Prefix } from 'src/app/models/prefix.model';
import { PrefixService } from 'src/app/services/prefix.service';
import { PrefixDetailsComponent} from 'src/app/components/prefix-details/prefix-details.component';
@Component({
selector: 'app-prefix-list',
providers: [PrefixDetailsComponent],
templateUrl: './prefix-list.component.html',
styleUrls: ['./prefix-list.component.scss']
})
export class PrefixListComponent implements OnInit {
prefixs?: Prefix[];
constructor(
private prefixService: PrefixService,
private prefixDetails: PrefixDetailsComponent,
private route: ActivatedRoute,
private router: Router) { }
constructor() { }
ngOnInit(): void {
this.getAllPrefix(this.route.snapshot.params.id);
//console.log("The boilerplate", this.route.snapshot.params.id);
}
getAllPrefix(id: string): void {
this.prefixService.getAll(id)
.subscribe(
data => {
this.prefixs = data;
//console.log(data);
for (var val of data) {
this.prefixDetails.getPrefix(id, val.id);
}
},
error => {
console.log(error);
});
}
}
export class Prefix {
id?:any;
prefix_group?:any;
prefix_boilerplate?:any;
prefix?: string;
system_fun_item?: string;
state_or_verb?: string;
item_function_flow_statevalue?: string;
logical_expression?: string;
logic_connective?: string;
simple_prefix?: string;
}
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Prefix } from '../models/prefix.model';
const baseUrl = 'http://155.207.131.19:8000/api-auth/boilerplates/';
const Url = '/prefix/';
@Injectable({
providedIn: 'root'
})
export class PrefixService {
constructor() { }
constructor(private http: HttpClient) { }
getAll(boilerplate: any): Observable<Prefix[]> {
return this.http.get<Prefix[]>(`${baseUrl}${boilerplate}${Url}`);
}
get(boilerplate: any, id: any): Observable<Prefix> {
return this.http.get(`${baseUrl}${boilerplate}${Url}${id}`);
}
create(boilerplate: any, data: any): Observable<any> {
return this.http.post(`${baseUrl}${boilerplate}${Url}`, data);
}
update(boilerplate: any, id: any, data: any): Observable<any> {
return this.http.put(`${baseUrl}${boilerplate}${Url}${id}/`, data);
}
delete(boilerplate: any, id: any): Observable<any> {
return this.http.delete(`${baseUrl}${boilerplate}${Url}${baseUrl}${id}`);
}
getsimpleprefix(): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/prefix/choices/simpleprefix/`);
}
getlogcon(): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/prefix/choices/logicalconnectivity/`);
}
getverb(): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/prefix/choices/verbprefix/`);
}
getsubject(): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/prefix/choices/sysfunitem/`);
}
getoobject(): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/prefix/choices/staflowfunitem/`);
}
//findByTitle(title: any): Observable<Prefix[]> {
// return this.http.get<Prefix[]>(`${baseUrl}title=${title}`);
//}
}
from rest_framework import serializers
from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate
class BoilerplateSerializer(serializers.ModelSerializer):
owner = serializers.ReadOnlyField(source='owner.username')
class Meta:
......@@ -14,3 +15,5 @@ class PrefixSerializer(serializers.ModelSerializer):
class Meta:
model = Prefix
fields = '__all__'
from django.urls import path, re_path
from django.conf.urls import url
from .views import user_views, requirements_views, main_req_views, suffix_req_views
urlpatterns = [
......@@ -21,4 +22,11 @@ urlpatterns = [
path('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'),
#PREFIX CHOICES DATA
path('prefix/choices/simpleprefix/', requirements_views.PrefixChoicesViewSet.as_view(), name='simpleprefixchoices'),
path('prefix/choices/logicalconnectivity/', requirements_views.LogConChoicesViewSet.as_view(), name='logicalconnectivitychoices'),
path('prefix/choices/verbprefix/', requirements_views.VerbChoicesViewSet.as_view(), name='verbprefixchoices'),
path('prefix/choices/sysfunitem/', requirements_views.FunItemSysChoicesViewSet.as_view(), name='sysfunitem'),
path('prefix/choices/staflowfunitem/', requirements_views.StaFlowFunItemChoicesViewSet.as_view(), name='staflowfunitem'),
]
\ No newline at end of file
......@@ -5,10 +5,14 @@ from django.http import HttpResponse, JsonResponse
from django.views.decorators.csrf import csrf_exempt
from rest_framework.parsers import JSONParser
from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate
from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate, 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 ITEM_CHOICES, FLOW_CHOICES, FUNCTION_CHOICES, STATE_VALUE_CHOICES
from reqman.apps.reqtool.rest_api.serializers.requirements import PrefixSerializer, BoilerplateSerializer
from reqman.apps.permissions import IsOwnerOrReadOnly
from reqman.apps.reqtool.rest_api.services import fuseki
from rest_framework.response import Response
from rest_framework.views import APIView
from django.shortcuts import get_object_or_404
......@@ -81,7 +85,7 @@ class PrefixListAPIView(ListAPIView):
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
serializer_class = PrefixSerializer
#
queryset = Prefix.objects.all()
#queryset = Prefix.objects.all()
def get_queryset(self):
group_pk = self.kwargs['boilerplate']
......@@ -127,3 +131,32 @@ class PrefixDetailsAPIView(RetrieveUpdateDestroyAPIView):
#print("deleted")
instance.delete()
class PrefixChoicesViewSet(APIView):
def get(self, request):
response = Response(PREFIX_CHOICES)
return response
class LogConChoicesViewSet(APIView):
def get(self, request):
response = Response(LOGIC_CONNECTIVE)
return response
class VerbChoicesViewSet(APIView):
def get(self, request):
response = Response(STATE_CHOICES + VERB_CHOICES)
return response
class FunItemSysChoicesViewSet(APIView):
def get(self, request):
response = Response(ITEM_CHOICES + SYSTEM_CHOICES + FUNCTION_CHOICES)
return response
class StaFlowFunItemChoicesViewSet(APIView):
def get(self, request):
response = Response(ITEM_CHOICES + FLOW_CHOICES + FUNCTION_CHOICES + STATE_VALUE_CHOICES)
return response
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