Commit 68e6abca authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

new table for data to show in frontend

parent 11f7574f
......@@ -48,6 +48,7 @@ export class BoilerplateDetailsComponent implements OnInit {
response => {
console.log(response);
this.message = response.message;
window.location.reload();
},
error => {
console.log(error);
......
......@@ -20,44 +20,44 @@
</div>
</div>
</div>
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<table mat-table [dataSource]="newdataSource" class="mat-elevation-z8">
<!-- Position Column -->
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef> No. </th>
<td mat-cell *matCellDef="let element"> {{element.id}} </td>
</ng-container>
<!-- Position Column -->
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef> No. </th>
<td mat-cell *matCellDef="let element"> {{element.id}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="title">
<th mat-header-cell *matHeaderCellDef> Title </th>
<td mat-cell *matCellDef="let element"> {{element.title}} </td>
</ng-container>
<!-- Weight Column -->
<ng-container matColumnDef="has_prefix">
<th mat-header-cell *matHeaderCellDef> Prefix </th>
<td mat-cell *matCellDef="let element"> {{element.has_prefix}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="prefix_data">
<th mat-header-cell *matHeaderCellDef> Prefix </th>
<td mat-cell *matCellDef="let element"> {{element.prefix_data}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="title_data">
<th mat-header-cell *matHeaderCellDef> Title </th>
<td mat-cell *matCellDef="let element"> {{element.title_data}} </td>
</ng-container>
<!-- Symbol Column -->
<ng-container matColumnDef="has_main">
<th mat-header-cell *matHeaderCellDef> Main </th>
<td mat-cell *matCellDef="let element"> {{element.has_main}} </td>
</ng-container>
<!-- Symbol Column -->
<ng-container matColumnDef="has_suffix">
<th mat-header-cell *matHeaderCellDef> Suffix </th>
<td mat-cell *matCellDef="let element"> {{element.has_suffix}} </td>
</ng-container>
<ng-container matColumnDef="main_data">
<th mat-header-cell *matHeaderCellDef> Main </th>
<td mat-cell *matCellDef="let element"> {{element.main_data}} </td>
</ng-container>
<!-- Action Column -->
<ng-container matColumnDef="action">
<th mat-header-cell *matHeaderCellDef> Action </th>
<td mat-cell *matCellDef="let element" class="action-link">
<a class="badge badge-warning" routerLink="/boilerplates/{{ element.id }}">Edit</a>
</td>
</ng-container>
<ng-container matColumnDef="suffix_data">
<th mat-header-cell *matHeaderCellDef> Suffix </th>
<td mat-cell *matCellDef="let element"> {{element.suffix_data}} </td>
</ng-container>
<!-- Action Column -->
<ng-container matColumnDef="action">
<th mat-header-cell *matHeaderCellDef> Action </th>
<td mat-cell *matCellDef="let element" class="action-link">
<a class="badge badge-warning" routerLink="/boilerplates/{{ element.id }}">Edit</a>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
<tr mat-header-row *matHeaderRowDef="newdisplayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: newdisplayedColumns;"></tr>
</table>
import { Component, OnInit } from '@angular/core';
import { Boilerplate } from 'src/app/models/boilerplate.model';
import { BoilerplateData } from 'src/app/models/boilerplate.model';
import { BoilerplateService } from 'src/app/services/boilerplate.service';
import { PrefixService } from 'src/app/services/prefix.service';
......@@ -13,16 +15,26 @@ import { BoilerplateService } from 'src/app/services/boilerplate.service';
export class BoilerplateListComponent implements OnInit {
boilerplates?: Boilerplate[];
boilerplatesdata?: BoilerplateData[];
currentBoilerplate?: Boilerplate;
currentBoilerplatedata?: BoilerplateData;
currentIndex = -1;
title = '';
displayedColumns: string[] = ['id', 'title', 'has_prefix', 'has_main', 'has_suffix', 'action'];
newdisplayedColumns: string[] = ['id','title_data' ,'prefix_data', 'main_data', 'suffix_data', 'action'];
dataSource :Boilerplate[] = [{}];
newdataSource:BoilerplateData[] = [{}];
dataofboilerplates: any [] = [];
aprefix: any [] = [];
main: any;
suffix: any;
constructor(private boilerplateService: BoilerplateService) { }
constructor(private boilerplateService: BoilerplateService, private prefixService: PrefixService) { }
ngOnInit(): void {
this.retrieveBoilerplates();
this.retrieve();
}
retrieveBoilerplates(): void {
......@@ -38,6 +50,21 @@ export class BoilerplateListComponent implements OnInit {
}
retrieve(): void {
this.boilerplateService.getAllData()
.subscribe(
data => {
this.boilerplatesdata =data;
this.newdataSource = data;
console.log(data)
},
error => {
console.log(error);
});
}
refreshList(): void {
this.retrieveBoilerplates();
this.currentBoilerplate = undefined;
......
......@@ -5,3 +5,11 @@ export class Boilerplate {
has_main?: boolean;
has_suffix?: boolean;
}
export class BoilerplateData {
id?:any;
title_data?: string;
prefix_data?: string;
main_data?: string;
suffix_data?: string;
}
\ No newline at end of file
......@@ -17,6 +17,10 @@ export class BoilerplateService {
return this.http.get<Boilerplate[]>(baseUrl);
}
getAllData(): Observable<Boilerplate[]> {
return this.http.get<Boilerplate[]>(baseUrl + `boilerplatedata/`);
}
get(id: any): Observable<Boilerplate> {
return this.http.get(`${baseUrl}${id}`);
}
......
......@@ -55,6 +55,9 @@ def create_prefix(instance):
prefix = Prefix(prefix_boilerplate = instance.boilerplate, prefixgroup = instance)
prefix.save()
def create_data(instance):
data = BoilerplateData(boilerplate_data_id = instance, owner_data = instance.owner, title_data= instance.title)
data.save()
def create_extra_prefix(instance, now_prefix):
prefix = Prefix(prefixgroup = instance.prefixgroup, prefix_boilerplate = instance.prefix_boilerplate)
......@@ -68,15 +71,38 @@ class Boilerplate(models.Model):
has_prefix = models.BooleanField(default=False)
has_main = models.BooleanField(default=False)
has_suffix = models.BooleanField(default=False)
def __init__(self, *args, **kwargs):
super(Boilerplate, self).__init__(*args, **kwargs)
self.__important_fields = ['has_prefix', 'has_main', 'has_suffix']
for field in self.__important_fields:
setattr(self, '__original_%s' % field, getattr(self, field))
def save(self, **kwargs):
"""Create prefix, main or suffix """
super(Boilerplate, self).save(**kwargs)
prev_prefix_list = []
for field in self.__important_fields:
orig = '__original_%s' % field
previous_simple_prefix = getattr(self, orig)
prev_prefix_list.append(previous_simple_prefix)
create_prefixgroup(self)
create_main(self)
create_suffix(self)
if (prev_prefix_list[0] == True and self.has_prefix == False ):
pr = ""
BoilerplateData.objects.filter(owner_data=self.owner, boilerplate_data_id = self).update(prefix_data = pr )
elif (prev_prefix_list[1] == True and self.has_main == False ):
pr = ""
BoilerplateData.objects.filter(owner_data=self.owner, boilerplate_data_id = self).update(main_data = pr )
elif (prev_prefix_list[2] == True and self.has_suffix == False ):
pr = ""
BoilerplateData.objects.filter(owner_data=self.owner, boilerplate_data_id = self).update(suffix_data = pr )
elif(BoilerplateData.objects.filter(owner_data=self.owner, boilerplate_data_id = self).count() != 1):
create_data(self)
class Meta:
ordering = ['created']
......@@ -134,3 +160,14 @@ class Prefix(models.Model):
class Meta:
ordering = ['prefix_boilerplate']
class BoilerplateData(models.Model):
owner_data = models.ForeignKey(User, related_name='boilerplate_data', 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)
prefix_data = models.CharField(default="", max_length=100, blank=True)
main_data = models.CharField(default="", max_length=100, blank=True)
suffix_data = models.CharField(max_length=100, blank=True)
class Meta:
ordering = ['boilerplate_data_id']
\ No newline at end of file
......@@ -16,10 +16,10 @@ SUFFIX_CHOICES = (("",""), ('S1', 'S1: <numerical-affirmative> j <closed-interva
('S5', 'S5: at even intervals'),
('S6', 'S6: sequentially')
)
NUMERICAL_AFFIRMATIVE_CHOICES = (("more than", "MORE THAN"), ("less than", "LESS THAN"), ("exactly","EXACTLY"),
("at least", "AT LEAST"), ("at most", "AT MOST"))
NUMBER_UNITS_CHOICES = (("",""), ("meters","METERS"), ("kilometers","KILOMETERS"), ("volt","VOLT"))
TIME_UNITS_CHOICES = (("seconds","SECONDS"), ("minutes","MINUTES"), ("milliseconds","MILLISECONDS"))
NUMERICAL_AFFIRMATIVE_CHOICES = (("MORE THAN", "MORE THAN"), ("LESS THAN", "LESS THAN"), ("EXACTLY","EXACTLY"),
("AT LEAST", "AT LEAST"), ("AT MOST", "AT MOST"))
NUMBER_UNITS_CHOICES = (("",""), ("METERS","METERS"), ("KILOMETERS","KILOMETERS"), ("VOLT","VOLT"))
TIME_UNITS_CHOICES = (("SECONDS","SECONDS"), ("MINUTES","MINUTES"), ("MILLISECONDS","MILLISECONDS"))
FLOW_CHOICES = get_instances("SAO#Flow")
# FLOW returns ()
S2_CHOICES = (("before","BEFORE"), ("after","AFTER"))
......
......@@ -3,7 +3,7 @@ from reqman.apps.reqtool.models.main_req import Main
class MainSerializer(serializers.ModelSerializer):
boilerplate_of_main = serializers.PrimaryKeyRelatedField(read_only=True)
#boilerplate_of_main = serializers.PrimaryKeyRelatedField(read_only=True)
main_owner = serializers.PrimaryKeyRelatedField(read_only=True)
class Meta:
model = Main
......
from rest_framework import serializers
from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate
from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate, BoilerplateData
class BoilerplateSerializer(serializers.ModelSerializer):
......@@ -10,10 +10,16 @@ class BoilerplateSerializer(serializers.ModelSerializer):
class PrefixSerializer(serializers.ModelSerializer):
prefix_boilerplate = serializers.PrimaryKeyRelatedField(read_only=True)
#prefix_boilerplate = serializers.PrimaryKeyRelatedField(read_only=True)
prefixgroup = serializers.PrimaryKeyRelatedField(read_only=True)
class Meta:
model = Prefix
fields = '__all__'
class BoilerplateDataSerializer(serializers.ModelSerializer):
owner_data = serializers.ReadOnlyField(source='owner.username')
boilerplate_data_id = serializers.PrimaryKeyRelatedField(read_only=True)
class Meta:
model = BoilerplateData
fields = '__all__'
......@@ -3,7 +3,7 @@ from reqman.apps.reqtool.models.suffix_req import Suffix
class SuffixSerializer(serializers.ModelSerializer):
boilerplate_of_suffix = serializers.PrimaryKeyRelatedField(read_only=True)
#boilerplate_of_suffix = serializers.PrimaryKeyRelatedField(read_only=True)
suffix_owner = serializers.PrimaryKeyRelatedField(read_only=True)
class Meta:
model = Suffix
......
......@@ -9,6 +9,7 @@ urlpatterns = [
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('boilerplates/<int:pk>/', requirements_views.BoilerplateDetailsAPIView.as_view(), name='api-requirements-details'),
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'),
#'''Prefix'''
......
......@@ -18,6 +18,8 @@ from reqman.apps.reqtool.models.main_req import SYSTEM_CHOICES, FUNCTION_CHOICES
from reqman.apps.reqtool.models.main_req import STATE_VALUE_CHOICES, SHALL_CHOICES, VERB_CHOICES, QUANTIFIER_CHOICES, NUMBER_UNITS_CHOICES
from reqman.apps.reqtool.models.main_req import FLOW_CHOICES, CONNECTION_CHOICES, STATE_SET_CHOICES
from reqman.apps.reqtool.models.requirements import BoilerplateData
class MainListAPIView(ListAPIView):
"""
API view to retrieve list of posts or create new
......@@ -56,6 +58,10 @@ class MainDetailsAPIView(RetrieveUpdateDestroyAPIView):
#Custom actions when PUT
def perform_update(self, serializer):
instance = serializer.validated_data
#add data in thn Model BoilerplateData
mn = (instance['sys_fun_inter'] + ' ' + instance['shall'] + ' ' + instance['verb'] + ' ' + instance['flow_function_interface_item_system_state_stateset'])
BoilerplateData.objects.filter(owner_data=instance['boilerplate_of_main'].owner, boilerplate_data_id = instance['boilerplate_of_main']).update(main_data = mn )
serializer.save()
#print(self.new.changed_data)
#instance = serializer.save()
......@@ -64,7 +70,7 @@ class MainDetailsAPIView(RetrieveUpdateDestroyAPIView):
#Custom actions when DELETE
def perform_destroy(self, instance):
#print("deleted")
#instance = serializer.validated_data
instance.delete()
......
......@@ -8,12 +8,13 @@ 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 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.reqtool.rest_api.serializers.requirements import BoilerplateSerializer, PrefixSerializer, BoilerplateDataSerializer
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 reqman.apps.reqtool.models.requirements import BoilerplateData
from django.shortcuts import get_object_or_404
class BoilerplateListCreateAPIView(ListCreateAPIView):
......@@ -117,20 +118,35 @@ class PrefixDetailsAPIView(RetrieveUpdateDestroyAPIView):
#Custom actions when PUT
def perform_update(self, serializer):
#print(self.new.changed_data)
instance = serializer.validated_data
#add data in thn Model BoilerplateData
pr = (instance['prefix'] + ' ' + instance['system_fun_item'] + ' ' + instance['state_or_verb'] + ' ' + instance['item_function_flow_statevalue'])
BoilerplateData.objects.filter(owner_data=instance['prefix_boilerplate'].owner, boilerplate_data_id = instance['prefix_boilerplate']).update(prefix_data = pr )
sprefix = self.simple_prefix(instance["prefix"])
#instance = serializer.save()
#write_fuseki = fuseki.FusekiActions()
#write_fuseki.write(serializer.data)
serializer.save(simple_prefix = sprefix)
#Custom actions when DELETE
def perform_destroy(self, instance):
instance = serializer.validated_data
#print("deleted")
instance.delete()
class BoilerplateDataListAPIView(ListAPIView):
"""
API view to retrieve list of posts or create new
"""
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
serializer_class = BoilerplateDataSerializer
#queryset = Prefix.objects.all()
def get_queryset(self):
#print(title)
queryset_boil_data = BoilerplateData.objects.filter(owner_data = self.request.user)
return queryset_boil_data
class PrefixChoicesViewSet(APIView):
def get(self, request):
......
......@@ -15,6 +15,7 @@ from rest_framework.response import Response
from rest_framework.views import APIView
from reqman.apps.reqtool.models.suffix_req import S_CHOICES, NUMBER_UNITS_CHOICES, TIME_UNITS_CHOICES, FLOW_CHOICES
from reqman.apps.reqtool.models.requirements import BoilerplateData
class SuffixListAPIView(ListAPIView):
......@@ -55,6 +56,10 @@ class SuffixDetailsAPIView(RetrieveUpdateDestroyAPIView):
#Custom actions when PUT
def perform_update(self, serializer):
instance = serializer.validated_data
#add data in thn Model BoilerplateData
sf = (instance['s_choices'] + ' ' + str(instance['numerical']) + ' ' + instance['mumerical_units'] + ' ' + instance['flow'])
BoilerplateData.objects.filter(owner_data=instance['boilerplate_of_suffix'].owner, boilerplate_data_id = instance['boilerplate_of_suffix']).update(suffix_data = sf )
serializer.save()
#print(self.new.changed_data)
#instance = serializer.save()
......@@ -63,6 +68,8 @@ class SuffixDetailsAPIView(RetrieveUpdateDestroyAPIView):
#Custom actions when DELETE
def perform_destroy(self, instance):
instance = serializer.validated_data
#add data in thn Model BoilerplateData
#print("deleted")
instance.delete()
......
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