mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-08-13 20:30:36 +03:00
R: Rename reference operation -> replica
This commit is contained in:
parent
b63a1d8454
commit
d4c7951966
|
@ -60,9 +60,9 @@ class InheritanceAdmin(admin.ModelAdmin):
|
|||
search_fields = ['id', 'operation', 'parent', 'child']
|
||||
|
||||
|
||||
@admin.register(models.Reference)
|
||||
class ReferenceAdmin(admin.ModelAdmin):
|
||||
''' Admin model: Reference. '''
|
||||
ordering = ['reference', 'target']
|
||||
list_display = ['id', 'reference', 'target']
|
||||
search_fields = ['id', 'reference', 'target']
|
||||
@admin.register(models.Replica)
|
||||
class ReplicaAdmin(admin.ModelAdmin):
|
||||
''' Admin model: Replica. '''
|
||||
ordering = ['replica', 'original']
|
||||
list_display = ['id', 'replica', 'original']
|
||||
search_fields = ['id', 'replica', 'original']
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
# Generated by Django 5.2.4 on 2025-08-06 09:10
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('oss', '0015_reference'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='operation',
|
||||
name='operation_type',
|
||||
field=models.CharField(choices=[('input', 'Input'), ('synthesis', 'Synthesis'), ('replica', 'Replica')], default='input', max_length=10, verbose_name='Тип'),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Replica',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('original', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='targets', to='oss.operation', verbose_name='Целевая Операция')),
|
||||
('replica', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='replicas', to='oss.operation', verbose_name='Реплика')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Реплика',
|
||||
'verbose_name_plural': 'Реплики',
|
||||
'unique_together': {('replica', 'original')},
|
||||
},
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='Reference',
|
||||
),
|
||||
]
|
|
@ -16,7 +16,7 @@ from django.db.models import (
|
|||
from apps.library.models import LibraryItem
|
||||
|
||||
from .Argument import Argument
|
||||
from .Reference import Reference
|
||||
from .Replica import Replica
|
||||
from .Substitution import Substitution
|
||||
|
||||
|
||||
|
@ -24,7 +24,7 @@ class OperationType(TextChoices):
|
|||
''' Type of operation. '''
|
||||
INPUT = 'input'
|
||||
SYNTHESIS = 'synthesis'
|
||||
REFERENCE = 'reference'
|
||||
REPLICA = 'replica'
|
||||
|
||||
|
||||
class Operation(Model):
|
||||
|
@ -93,13 +93,13 @@ class Operation(Model):
|
|||
''' Operation substitutions. '''
|
||||
return Substitution.objects.filter(operation=self)
|
||||
|
||||
def getQ_references(self) -> QuerySet[Reference]:
|
||||
''' Operation references. '''
|
||||
return Reference.objects.filter(target=self)
|
||||
def getQ_replicas(self) -> QuerySet[Replica]:
|
||||
''' Operation replicas. '''
|
||||
return Replica.objects.filter(original=self)
|
||||
|
||||
def getQ_reference_target(self) -> list['Operation']:
|
||||
''' Operation target for current reference. '''
|
||||
return [x.target for x in Reference.objects.filter(reference=self)]
|
||||
def getQ_replica_original(self) -> list['Operation']:
|
||||
''' Operation source for current replica. '''
|
||||
return [x.original for x in Replica.objects.filter(replica=self)]
|
||||
|
||||
def setQ_result(self, result: Optional[LibraryItem]) -> None:
|
||||
''' Set result schema. '''
|
||||
|
@ -107,12 +107,12 @@ class Operation(Model):
|
|||
return
|
||||
self.result = result
|
||||
self.save(update_fields=['result'])
|
||||
for reference in self.getQ_references():
|
||||
reference.reference.result = result
|
||||
reference.reference.save(update_fields=['result'])
|
||||
for rep in self.getQ_replicas():
|
||||
rep.replica.result = result
|
||||
rep.replica.save(update_fields=['result'])
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
''' Delete operation. '''
|
||||
for ref in self.getQ_references():
|
||||
ref.reference.delete()
|
||||
for rep in self.getQ_replicas():
|
||||
rep.replica.delete()
|
||||
super().delete(*args, **kwargs)
|
||||
|
|
|
@ -11,7 +11,7 @@ from .Block import Block
|
|||
from .Inheritance import Inheritance
|
||||
from .Layout import Layout
|
||||
from .Operation import Operation, OperationType
|
||||
from .Reference import Reference
|
||||
from .Replica import Replica
|
||||
from .Substitution import Substitution
|
||||
|
||||
|
||||
|
@ -67,15 +67,15 @@ class OperationSchema:
|
|||
result = Operation.objects.create(oss=self.model, **kwargs)
|
||||
return result
|
||||
|
||||
def create_reference(self, target: Operation) -> Operation:
|
||||
''' Create Reference Operation. '''
|
||||
def create_replica(self, target: Operation) -> Operation:
|
||||
''' Create Replica Operation. '''
|
||||
result = Operation.objects.create(
|
||||
oss=self.model,
|
||||
operation_type=OperationType.REFERENCE,
|
||||
operation_type=OperationType.REPLICA,
|
||||
result=target.result,
|
||||
parent=target.parent
|
||||
)
|
||||
Reference.objects.create(reference=result, target=target)
|
||||
Replica.objects.create(replica=result, original=target)
|
||||
return result
|
||||
|
||||
def create_block(self, **kwargs) -> Block:
|
||||
|
|
|
@ -24,17 +24,17 @@ class OperationSchemaCached:
|
|||
self.cache = OssCache(model.pk)
|
||||
self.engine = PropagationEngine(self.cache)
|
||||
|
||||
def delete_reference(self, target: int, keep_connections: bool = False, keep_constituents: bool = False):
|
||||
''' Delete Reference Operation. '''
|
||||
def delete_replica(self, target: int, keep_connections: bool = False, keep_constituents: bool = False):
|
||||
''' Delete Replica Operation. '''
|
||||
if not keep_connections:
|
||||
self.delete_operation(target, keep_constituents)
|
||||
return
|
||||
self.cache.ensure_loaded_subs()
|
||||
operation = self.cache.operation_by_id[target]
|
||||
reference_target = self.cache.reference_target.get(target)
|
||||
if reference_target:
|
||||
original = self.cache.replica_original.get(target)
|
||||
if original:
|
||||
for arg in operation.getQ_as_argument():
|
||||
arg.argument_id = reference_target
|
||||
arg.argument_id = original
|
||||
arg.save()
|
||||
self.cache.remove_operation(target)
|
||||
operation.delete()
|
||||
|
|
|
@ -8,7 +8,7 @@ from apps.rsform.models import RSFormCached
|
|||
from .Argument import Argument
|
||||
from .Inheritance import Inheritance
|
||||
from .Operation import Operation, OperationType
|
||||
from .Reference import Reference
|
||||
from .Replica import Replica
|
||||
from .Substitution import Substitution
|
||||
|
||||
|
||||
|
@ -28,8 +28,8 @@ class OssCache:
|
|||
self.graph.add_node(operation.pk)
|
||||
self.extend_graph.add_node(operation.pk)
|
||||
|
||||
references = Reference.objects.filter(reference__oss_id=self._item_id).only('reference_id', 'target_id')
|
||||
self.reference_target = {ref.reference_id: ref.target_id for ref in references}
|
||||
replicas = Replica.objects.filter(replica__oss_id=self._item_id).only('replica_id', 'original_id')
|
||||
self.replica_original = {rep.replica_id: rep.original_id for rep in replicas}
|
||||
arguments = Argument.objects \
|
||||
.filter(operation__oss_id=self._item_id) \
|
||||
.only('operation_id', 'argument_id') \
|
||||
|
@ -37,9 +37,9 @@ class OssCache:
|
|||
for argument in arguments:
|
||||
self.graph.add_edge(argument.argument_id, argument.operation_id)
|
||||
self.extend_graph.add_edge(argument.argument_id, argument.operation_id)
|
||||
target = self.reference_target.get(argument.argument_id)
|
||||
if target is not None:
|
||||
self.extend_graph.add_edge(target, argument.operation_id)
|
||||
original = self.replica_original.get(argument.argument_id)
|
||||
if original is not None:
|
||||
self.extend_graph.add_edge(original, argument.operation_id)
|
||||
|
||||
self.is_loaded_subs = False
|
||||
self.substitutions: dict[int, list[Substitution]] = {}
|
||||
|
@ -85,7 +85,7 @@ class OssCache:
|
|||
def get_operation(self, schemaID: int) -> Operation:
|
||||
''' Get operation by schema. '''
|
||||
for operation in self.operations:
|
||||
if operation.result_id == schemaID and operation.operation_type != OperationType.REFERENCE:
|
||||
if operation.result_id == schemaID and operation.operation_type != OperationType.REPLICA:
|
||||
return operation
|
||||
raise ValueError(f'Operation for schema {schemaID} not found')
|
||||
|
||||
|
@ -121,7 +121,7 @@ class OssCache:
|
|||
''' Insert new argument. '''
|
||||
self.graph.add_edge(argument.argument_id, argument.operation_id)
|
||||
self.extend_graph.add_edge(argument.argument_id, argument.operation_id)
|
||||
target = self.reference_target.get(argument.argument_id)
|
||||
target = self.replica_original.get(argument.argument_id)
|
||||
if target is not None:
|
||||
self.extend_graph.add_edge(target, argument.operation_id)
|
||||
|
||||
|
@ -160,8 +160,8 @@ class OssCache:
|
|||
del self._schema_by_id[target.result_id]
|
||||
self.operations.remove(self.operation_by_id[operation])
|
||||
del self.operation_by_id[operation]
|
||||
if operation in self.reference_target:
|
||||
del self.reference_target[operation]
|
||||
if operation in self.replica_original:
|
||||
del self.replica_original[operation]
|
||||
if self.is_loaded_subs:
|
||||
del self.substitutions[operation]
|
||||
del self.inheritance[operation]
|
||||
|
@ -170,7 +170,7 @@ class OssCache:
|
|||
''' Remove argument from cache. '''
|
||||
self.graph.remove_edge(argument.argument_id, argument.operation_id)
|
||||
self.extend_graph.remove_edge(argument.argument_id, argument.operation_id)
|
||||
target = self.reference_target.get(argument.argument_id)
|
||||
target = self.replica_original.get(argument.argument_id)
|
||||
if target is not None:
|
||||
if not Argument.objects.filter(argument_id=target, operation_id=argument.operation_id).exists():
|
||||
self.extend_graph.remove_edge(target, argument.operation_id)
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
''' Models: Operation Reference in OSS. '''
|
||||
from django.db.models import CASCADE, ForeignKey, Model
|
||||
|
||||
|
||||
class Reference(Model):
|
||||
''' Operation Reference. '''
|
||||
reference = ForeignKey(
|
||||
verbose_name='Отсылка',
|
||||
to='oss.Operation',
|
||||
on_delete=CASCADE,
|
||||
related_name='references'
|
||||
)
|
||||
target = ForeignKey(
|
||||
verbose_name='Целевая Операция',
|
||||
to='oss.Operation',
|
||||
on_delete=CASCADE,
|
||||
related_name='targets'
|
||||
)
|
||||
|
||||
class Meta:
|
||||
''' Model metadata. '''
|
||||
verbose_name = 'Отсылка'
|
||||
verbose_name_plural = 'Отсылки'
|
||||
unique_together = [['reference', 'target']]
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f'{self.reference} -> {self.target}'
|
27
rsconcept/backend/apps/oss/models/Replica.py
Normal file
27
rsconcept/backend/apps/oss/models/Replica.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
''' Models: Operation Replica in OSS. '''
|
||||
from django.db.models import CASCADE, ForeignKey, Model
|
||||
|
||||
|
||||
class Replica(Model):
|
||||
''' Operation Replica. '''
|
||||
replica = ForeignKey(
|
||||
verbose_name='Реплика',
|
||||
to='oss.Operation',
|
||||
on_delete=CASCADE,
|
||||
related_name='replicas'
|
||||
)
|
||||
original = ForeignKey(
|
||||
verbose_name='Целевая Операция',
|
||||
to='oss.Operation',
|
||||
on_delete=CASCADE,
|
||||
related_name='targets'
|
||||
)
|
||||
|
||||
class Meta:
|
||||
''' Model metadata. '''
|
||||
verbose_name = 'Реплика'
|
||||
verbose_name_plural = 'Реплики'
|
||||
unique_together = [['replica', 'original']]
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f'{self.replica} -> {self.original}'
|
|
@ -8,5 +8,5 @@ from .Operation import Operation, OperationType
|
|||
from .OperationSchema import OperationSchema
|
||||
from .OperationSchemaCached import OperationSchemaCached
|
||||
from .PropagationFacade import PropagationFacade
|
||||
from .Reference import Reference
|
||||
from .Replica import Replica
|
||||
from .Substitution import Substitution
|
||||
|
|
|
@ -6,18 +6,18 @@ from .data_access import (
|
|||
BlockSerializer,
|
||||
CloneSchemaSerializer,
|
||||
CreateBlockSerializer,
|
||||
CreateReferenceSerializer,
|
||||
CreateReplicaSerializer,
|
||||
CreateSchemaSerializer,
|
||||
CreateSynthesisSerializer,
|
||||
DeleteBlockSerializer,
|
||||
DeleteOperationSerializer,
|
||||
DeleteReferenceSerializer,
|
||||
DeleteReplicaSerializer,
|
||||
ImportSchemaSerializer,
|
||||
MoveItemsSerializer,
|
||||
OperationSchemaSerializer,
|
||||
OperationSerializer,
|
||||
ReferenceSerializer,
|
||||
RelocateConstituentsSerializer,
|
||||
ReplicaSerializer,
|
||||
SetOperationInputSerializer,
|
||||
TargetOperationSerializer,
|
||||
UpdateBlockSerializer,
|
||||
|
|
|
@ -20,7 +20,7 @@ from ..models import (
|
|||
Layout,
|
||||
Operation,
|
||||
OperationType,
|
||||
Reference,
|
||||
Replica,
|
||||
Substitution
|
||||
)
|
||||
from .basics import NodeSerializer, PositionSerializer, SubstitutionExSerializer
|
||||
|
@ -54,12 +54,12 @@ class ArgumentSerializer(StrictModelSerializer):
|
|||
fields = ('operation', 'argument')
|
||||
|
||||
|
||||
class ReferenceSerializer(StrictModelSerializer):
|
||||
''' Serializer: Reference data. '''
|
||||
class ReplicaSerializer(StrictModelSerializer):
|
||||
''' Serializer: Replica data. '''
|
||||
class Meta:
|
||||
''' serializer metadata. '''
|
||||
model = Reference
|
||||
fields = ('reference', 'target')
|
||||
model = Replica
|
||||
fields = ('replica', 'original')
|
||||
|
||||
|
||||
class CreateBlockSerializer(StrictSerializer):
|
||||
|
@ -251,15 +251,15 @@ class CloneSchemaSerializer(StrictSerializer):
|
|||
raise serializers.ValidationError({
|
||||
'source_operation': msg.operationResultEmpty(source_operation.alias)
|
||||
})
|
||||
if source_operation.operation_type == OperationType.REFERENCE:
|
||||
if source_operation.operation_type == OperationType.REPLICA:
|
||||
raise serializers.ValidationError({
|
||||
'source_operation': msg.referenceTypeNotAllowed()
|
||||
'source_operation': msg.replicaNotAllowed()
|
||||
})
|
||||
return attrs
|
||||
|
||||
|
||||
class CreateReferenceSerializer(StrictSerializer):
|
||||
''' Serializer: Create reference operation. '''
|
||||
class CreateReplicaSerializer(StrictSerializer):
|
||||
''' Serializer: Create Replica operation. '''
|
||||
layout = serializers.ListField(child=NodeSerializer())
|
||||
target = PKField(many=False, queryset=Operation.objects.all())
|
||||
position = PositionSerializer()
|
||||
|
@ -269,11 +269,11 @@ class CreateReferenceSerializer(StrictSerializer):
|
|||
target = cast(Operation, attrs['target'])
|
||||
if target.oss_id != oss.pk:
|
||||
raise serializers.ValidationError({
|
||||
'target_operation': msg.operationNotInOSS()
|
||||
'target': msg.operationNotInOSS()
|
||||
})
|
||||
if target.operation_type == OperationType.REFERENCE:
|
||||
if target.operation_type == OperationType.REPLICA:
|
||||
raise serializers.ValidationError({
|
||||
'target_operation': msg.referenceTypeNotAllowed()
|
||||
'target': msg.replicaNotAllowed()
|
||||
})
|
||||
return attrs
|
||||
|
||||
|
@ -432,7 +432,7 @@ class UpdateOperationSerializer(StrictSerializer):
|
|||
|
||||
|
||||
class DeleteOperationSerializer(StrictSerializer):
|
||||
''' Serializer: Delete non-reference operation. '''
|
||||
''' Serializer: Delete non-replica operation. '''
|
||||
layout = serializers.ListField(
|
||||
child=NodeSerializer()
|
||||
)
|
||||
|
@ -447,15 +447,15 @@ class DeleteOperationSerializer(StrictSerializer):
|
|||
raise serializers.ValidationError({
|
||||
'target': msg.operationNotInOSS()
|
||||
})
|
||||
if operation.operation_type == OperationType.REFERENCE:
|
||||
if operation.operation_type == OperationType.REPLICA:
|
||||
raise serializers.ValidationError({
|
||||
'target': msg.referenceTypeNotAllowed()
|
||||
'target': msg.replicaNotAllowed()
|
||||
})
|
||||
return attrs
|
||||
|
||||
|
||||
class DeleteReferenceSerializer(StrictSerializer):
|
||||
''' Serializer: Delete reference operation. '''
|
||||
class DeleteReplicaSerializer(StrictSerializer):
|
||||
''' Serializer: Delete Replica operation. '''
|
||||
layout = serializers.ListField(
|
||||
child=NodeSerializer()
|
||||
)
|
||||
|
@ -470,9 +470,9 @@ class DeleteReferenceSerializer(StrictSerializer):
|
|||
raise serializers.ValidationError({
|
||||
'target': msg.operationNotInOSS()
|
||||
})
|
||||
if operation.operation_type != OperationType.REFERENCE:
|
||||
if operation.operation_type != OperationType.REPLICA:
|
||||
raise serializers.ValidationError({
|
||||
'target': msg.referenceTypeRequired()
|
||||
'target': msg.replicaRequired()
|
||||
})
|
||||
return attrs
|
||||
|
||||
|
@ -535,8 +535,8 @@ class OperationSchemaSerializer(StrictModelSerializer):
|
|||
substitutions = serializers.ListField(
|
||||
child=SubstitutionExSerializer()
|
||||
)
|
||||
references = serializers.ListField(
|
||||
child=ReferenceSerializer()
|
||||
replicas = serializers.ListField(
|
||||
child=ReplicaSerializer()
|
||||
)
|
||||
layout = serializers.ListField(
|
||||
child=NodeSerializer()
|
||||
|
@ -555,7 +555,7 @@ class OperationSchemaSerializer(StrictModelSerializer):
|
|||
result['blocks'] = []
|
||||
result['arguments'] = []
|
||||
result['substitutions'] = []
|
||||
result['references'] = []
|
||||
result['replicas'] = []
|
||||
for operation in Operation.objects.filter(oss=instance).order_by('pk'):
|
||||
operation_data = OperationSerializer(operation).data
|
||||
operation_result = operation.result
|
||||
|
@ -578,8 +578,8 @@ class OperationSchemaSerializer(StrictModelSerializer):
|
|||
substitution_term=F('substitution__term_resolved'),
|
||||
).order_by('pk'):
|
||||
result['substitutions'].append(substitution)
|
||||
for reference in Reference.objects.filter(target__oss=instance).order_by('pk'):
|
||||
result['references'].append(ReferenceSerializer(reference).data)
|
||||
for replication in Replica.objects.filter(original__oss=instance).order_by('pk'):
|
||||
result['replicas'].append(ReplicaSerializer(replication).data)
|
||||
|
||||
return result
|
||||
|
||||
|
|
|
@ -3,5 +3,5 @@ from .t_Argument import *
|
|||
from .t_Inheritance import *
|
||||
from .t_Layout import *
|
||||
from .t_Operation import *
|
||||
from .t_Reference import *
|
||||
from .t_Replica import *
|
||||
from .t_Substitution import *
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
''' Testing models: Reference. '''
|
||||
''' Testing models: Replica. '''
|
||||
from django.test import TestCase
|
||||
|
||||
from apps.oss.models import Operation, OperationSchema, OperationType, Reference
|
||||
from apps.oss.models import Operation, OperationSchema, OperationType, Replica
|
||||
from apps.rsform.models import RSForm
|
||||
|
||||
|
||||
class TestReference(TestCase):
|
||||
''' Testing Reference model. '''
|
||||
class TestReplica(TestCase):
|
||||
''' Testing Replica model. '''
|
||||
|
||||
|
||||
def setUp(self):
|
||||
|
@ -19,26 +19,26 @@ class TestReference(TestCase):
|
|||
)
|
||||
self.operation2 = Operation.objects.create(
|
||||
oss=self.oss.model,
|
||||
operation_type=OperationType.REFERENCE,
|
||||
operation_type=OperationType.REPLICA,
|
||||
)
|
||||
self.reference = Reference.objects.create(
|
||||
reference=self.operation2,
|
||||
target=self.operation1
|
||||
self.replicas = Replica.objects.create(
|
||||
replica=self.operation2,
|
||||
original=self.operation1
|
||||
)
|
||||
|
||||
|
||||
def test_str(self):
|
||||
testStr = f'{self.operation2} -> {self.operation1}'
|
||||
self.assertEqual(str(self.reference), testStr)
|
||||
self.assertEqual(str(self.replicas), testStr)
|
||||
|
||||
|
||||
def test_cascade_delete_operation(self):
|
||||
self.assertEqual(Reference.objects.count(), 1)
|
||||
self.assertEqual(Replica.objects.count(), 1)
|
||||
self.operation2.delete()
|
||||
self.assertEqual(Reference.objects.count(), 0)
|
||||
self.assertEqual(Replica.objects.count(), 0)
|
||||
|
||||
|
||||
def test_cascade_delete_target(self):
|
||||
self.assertEqual(Reference.objects.count(), 1)
|
||||
self.assertEqual(Replica.objects.count(), 1)
|
||||
self.operation1.delete()
|
||||
self.assertEqual(Reference.objects.count(), 0)
|
||||
self.assertEqual(Replica.objects.count(), 0)
|
|
@ -50,7 +50,7 @@ class ReferencePropagationTestCase(EndpointTester):
|
|||
operation_type=OperationType.INPUT,
|
||||
result=self.ks2.model
|
||||
)
|
||||
self.operation3 = self.owned.create_reference(self.operation1)
|
||||
self.operation3 = self.owned.create_replica(self.operation1)
|
||||
|
||||
self.operation4 = self.owned.create_operation(
|
||||
alias='4',
|
||||
|
@ -175,8 +175,8 @@ class ReferencePropagationTestCase(EndpointTester):
|
|||
self.assertEqual(self.ks6.constituentsQ().count(), 5)
|
||||
|
||||
|
||||
@decl_endpoint('/api/oss/{item}/delete-reference', method='patch')
|
||||
def test_delete_reference_redirection(self):
|
||||
@decl_endpoint('/api/oss/{item}/delete-replica', method='patch')
|
||||
def test_delete_replica_redirection(self):
|
||||
data = {
|
||||
'layout': self.layout_data,
|
||||
'target': self.operation3.pk,
|
||||
|
@ -188,8 +188,8 @@ class ReferencePropagationTestCase(EndpointTester):
|
|||
self.assertEqual(self.ks5.constituentsQ().count(), 9)
|
||||
self.assertEqual(self.ks6.constituentsQ().count(), 6)
|
||||
|
||||
@decl_endpoint('/api/oss/{item}/delete-reference', method='patch')
|
||||
def test_delete_reference_constituents(self):
|
||||
@decl_endpoint('/api/oss/{item}/delete-replica', method='patch')
|
||||
def test_delete_replica_constituents(self):
|
||||
data = {
|
||||
'layout': self.layout_data,
|
||||
'target': self.operation3.pk,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
''' Testing API: Operation Schema - operations manipulation. '''
|
||||
from apps.library.models import AccessPolicy, Editor, LibraryItem, LibraryItemType
|
||||
from apps.oss.models import Argument, Operation, OperationSchema, OperationType, Reference
|
||||
from apps.oss.models import Argument, Operation, OperationSchema, OperationType, Replica
|
||||
from apps.rsform.models import Constituenta, RSForm
|
||||
from shared.EndpointTester import EndpointTester, decl_endpoint
|
||||
|
||||
|
@ -209,8 +209,8 @@ class TestOssOperations(EndpointTester):
|
|||
self.assertEqual(new_operation['parent'], block_owned.id)
|
||||
|
||||
|
||||
@decl_endpoint('/api/oss/{item}/create-reference', method='post')
|
||||
def test_create_reference(self):
|
||||
@decl_endpoint('/api/oss/{item}/create-replica', method='post')
|
||||
def test_create_replica(self):
|
||||
self.populateData()
|
||||
data = {
|
||||
'target': self.invalid_id,
|
||||
|
@ -232,10 +232,10 @@ class TestOssOperations(EndpointTester):
|
|||
self.owned.model.refresh_from_db()
|
||||
new_operation_id = response.data['new_operation']
|
||||
new_operation = next(op for op in response.data['oss']['operations'] if op['id'] == new_operation_id)
|
||||
self.assertEqual(new_operation['operation_type'], OperationType.REFERENCE)
|
||||
self.assertEqual(new_operation['operation_type'], OperationType.REPLICA)
|
||||
self.assertEqual(new_operation['parent'], self.operation1.parent_id)
|
||||
self.assertEqual(new_operation['result'], self.operation1.result_id)
|
||||
ref = Reference.objects.filter(reference_id=new_operation_id, target_id=self.operation1.pk).first()
|
||||
ref = Replica.objects.filter(replica_id=new_operation_id, original_id=self.operation1.pk).first()
|
||||
self.assertIsNotNone(ref)
|
||||
self.assertTrue(Operation.objects.filter(pk=new_operation_id, oss=self.owned.model).exists())
|
||||
|
||||
|
@ -301,7 +301,7 @@ class TestOssOperations(EndpointTester):
|
|||
@decl_endpoint('/api/oss/{item}/delete-operation', method='patch')
|
||||
def test_delete_reference_operation_invalid(self):
|
||||
self.populateData()
|
||||
reference_operation = self.owned.create_reference(self.operation1)
|
||||
reference_operation = self.owned.create_replica(self.operation1)
|
||||
data = {
|
||||
'layout': self.layout_data,
|
||||
'target': reference_operation.pk
|
||||
|
@ -309,8 +309,8 @@ class TestOssOperations(EndpointTester):
|
|||
self.executeBadData(data=data, item=self.owned_id)
|
||||
|
||||
|
||||
@decl_endpoint('/api/oss/{item}/delete-reference', method='patch')
|
||||
def test_delete_reference_operation(self):
|
||||
@decl_endpoint('/api/oss/{item}/delete-replica', method='patch')
|
||||
def test_delete_replica_operation(self):
|
||||
self.populateData()
|
||||
data = {
|
||||
'layout': self.layout_data,
|
||||
|
@ -318,8 +318,8 @@ class TestOssOperations(EndpointTester):
|
|||
}
|
||||
self.executeBadData(data=data, item=self.owned_id)
|
||||
|
||||
reference_operation = self.owned.create_reference(self.operation1)
|
||||
self.assertEqual(len(self.operation1.getQ_references()), 1)
|
||||
reference_operation = self.owned.create_replica(self.operation1)
|
||||
self.assertEqual(len(self.operation1.getQ_replicas()), 1)
|
||||
data['target'] = reference_operation.pk
|
||||
self.executeForbidden(data=data, item=self.unowned_id)
|
||||
|
||||
|
@ -328,7 +328,7 @@ class TestOssOperations(EndpointTester):
|
|||
|
||||
data['target'] = reference_operation.pk
|
||||
self.executeOK(data=data, item=self.owned_id)
|
||||
self.assertEqual(len(self.operation1.getQ_references()), 0)
|
||||
self.assertEqual(len(self.operation1.getQ_replicas()), 0)
|
||||
|
||||
|
||||
@decl_endpoint('/api/oss/{item}/create-input', method='patch')
|
||||
|
|
|
@ -65,11 +65,11 @@ class OssViewSet(viewsets.GenericViewSet, generics.ListAPIView, generics.Retriev
|
|||
'create_schema',
|
||||
'clone_schema',
|
||||
'import_schema',
|
||||
'create_reference',
|
||||
'create_replica',
|
||||
'create_synthesis',
|
||||
'update_operation',
|
||||
'delete_operation',
|
||||
'delete_reference',
|
||||
'delete_replica',
|
||||
'create_input',
|
||||
'set_input',
|
||||
'execute_operation',
|
||||
|
@ -465,9 +465,9 @@ class OssViewSet(viewsets.GenericViewSet, generics.ListAPIView, generics.Retriev
|
|||
|
||||
|
||||
@extend_schema(
|
||||
summary='create reference for operation',
|
||||
summary='create replica for operation',
|
||||
tags=['OSS'],
|
||||
request=s.CreateReferenceSerializer(),
|
||||
request=s.CreateReplicaSerializer(),
|
||||
responses={
|
||||
c.HTTP_201_CREATED: s.OperationCreatedResponse,
|
||||
c.HTTP_400_BAD_REQUEST: None,
|
||||
|
@ -475,11 +475,11 @@ class OssViewSet(viewsets.GenericViewSet, generics.ListAPIView, generics.Retriev
|
|||
c.HTTP_404_NOT_FOUND: None
|
||||
}
|
||||
)
|
||||
@action(detail=True, methods=['post'], url_path='create-reference')
|
||||
def create_reference(self, request: Request, pk) -> HttpResponse:
|
||||
''' Clone schema. '''
|
||||
@action(detail=True, methods=['post'], url_path='create-replica')
|
||||
def create_replica(self, request: Request, pk) -> HttpResponse:
|
||||
''' Replicate schema. '''
|
||||
item = self._get_item()
|
||||
serializer = s.CreateReferenceSerializer(
|
||||
serializer = s.CreateReplicaSerializer(
|
||||
data=request.data,
|
||||
context={'oss': item}
|
||||
)
|
||||
|
@ -490,7 +490,7 @@ class OssViewSet(viewsets.GenericViewSet, generics.ListAPIView, generics.Retriev
|
|||
with transaction.atomic():
|
||||
oss = m.OperationSchema(item)
|
||||
target = cast(m.Operation, serializer.validated_data['target'])
|
||||
new_operation = oss.create_reference(target)
|
||||
new_operation = oss.create_replica(target)
|
||||
layout.append({
|
||||
'nodeID': 'o' + str(new_operation.pk),
|
||||
'x': position['x'],
|
||||
|
@ -657,9 +657,9 @@ class OssViewSet(viewsets.GenericViewSet, generics.ListAPIView, generics.Retriev
|
|||
)
|
||||
|
||||
@extend_schema(
|
||||
summary='delete reference',
|
||||
summary='delete replica',
|
||||
tags=['OSS'],
|
||||
request=s.DeleteReferenceSerializer(),
|
||||
request=s.DeleteReplicaSerializer(),
|
||||
responses={
|
||||
c.HTTP_200_OK: s.OperationSchemaSerializer,
|
||||
c.HTTP_400_BAD_REQUEST: None,
|
||||
|
@ -667,11 +667,11 @@ class OssViewSet(viewsets.GenericViewSet, generics.ListAPIView, generics.Retriev
|
|||
c.HTTP_404_NOT_FOUND: None
|
||||
}
|
||||
)
|
||||
@action(detail=True, methods=['patch'], url_path='delete-reference')
|
||||
def delete_reference(self, request: Request, pk) -> HttpResponse:
|
||||
''' Endpoint: Delete Reference Operation. '''
|
||||
@action(detail=True, methods=['patch'], url_path='delete-replica')
|
||||
def delete_replica(self, request: Request, pk) -> HttpResponse:
|
||||
''' Endpoint: Delete Replica Operation. '''
|
||||
item = self._get_item()
|
||||
serializer = s.DeleteReferenceSerializer(
|
||||
serializer = s.DeleteReplicaSerializer(
|
||||
data=request.data,
|
||||
context={'oss': item}
|
||||
)
|
||||
|
@ -685,7 +685,7 @@ class OssViewSet(viewsets.GenericViewSet, generics.ListAPIView, generics.Retriev
|
|||
with transaction.atomic():
|
||||
oss = m.OperationSchemaCached(item)
|
||||
m.Layout.update_data(pk, layout)
|
||||
oss.delete_reference(operation.pk, keep_connections, keep_constituents)
|
||||
oss.delete_replica(operation.pk, keep_connections, keep_constituents)
|
||||
item.save(update_fields=['time_update'])
|
||||
|
||||
return Response(
|
||||
|
|
|
@ -86,12 +86,12 @@ def operationInputAlreadyConnected():
|
|||
return 'Схема уже подключена к другой операции'
|
||||
|
||||
|
||||
def referenceTypeNotAllowed():
|
||||
return 'Ссылки не поддерживаются'
|
||||
def replicaNotAllowed():
|
||||
return 'Реплики не поддерживаются'
|
||||
|
||||
|
||||
def referenceTypeRequired():
|
||||
return 'Операция должна быть ссылкой'
|
||||
def replicaRequired():
|
||||
return 'Операция должна быть репликацией'
|
||||
|
||||
|
||||
def operationNotSynthesis(title: str):
|
||||
|
|
|
@ -46,8 +46,8 @@ const DlgDeleteOperation = React.lazy(() =>
|
|||
}))
|
||||
);
|
||||
const DlgDeleteReference = React.lazy(() =>
|
||||
import('@/features/oss/dialogs/dlg-delete-reference').then(module => ({
|
||||
default: module.DlgDeleteReference
|
||||
import('@/features/oss/dialogs/dlg-delete-replica').then(module => ({
|
||||
default: module.DlgDeleteReplica
|
||||
}))
|
||||
);
|
||||
const DlgEditEditors = React.lazy(() =>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import {
|
||||
IconChild,
|
||||
IconConceptBlock,
|
||||
IconConsolidation,
|
||||
IconCrucial,
|
||||
IconCstAxiom,
|
||||
|
@ -254,12 +255,19 @@ export function HelpThesaurus() {
|
|||
</p>
|
||||
<p>Граф синтеза – ориентированный граф, где вершины — операции, а ребра — зависимости по результатам операций.</p>
|
||||
<p>
|
||||
<IconConceptBlock className='inline-icon' />
|
||||
{'\u2009'}
|
||||
<LinkTopic text='Концептуальный блок' topic={HelpTopic.CC_STRUCTURING} /> – номинально выделенная часть
|
||||
предметной области, формирующая границы для отнесения концептуальных схем в ОСС к различным аспектам предметной
|
||||
области.
|
||||
</p>
|
||||
|
||||
<p>Операция – выделенная часть ОСС, определяющая способ получения КС в рамках ОСС.</p>
|
||||
<p>
|
||||
<IconReference className='inline-icon' />
|
||||
{'\u2009'}Реплика – способ дублирования графического представления результата некоторой операции для улучшения
|
||||
визуального отображения путем сокращения длины связей между вершинами.
|
||||
</p>
|
||||
<p>
|
||||
<IconConsolidation className='inline-icon' />
|
||||
{'\u2009'}Ромбовидный синтез – операция, где используются КС, имеющие общих предков.
|
||||
|
@ -269,7 +277,7 @@ export function HelpThesaurus() {
|
|||
<b>Типы операций в ОСС</b>
|
||||
<li>
|
||||
<IconReference size='1rem' className='inline-icon' />
|
||||
{'\u2009'}отсылка на результат другой операции.
|
||||
{'\u2009'}репликация результата другой операции.
|
||||
</li>
|
||||
<li>
|
||||
<IconDownload size='1rem' className='inline-icon' />
|
||||
|
|
|
@ -146,7 +146,7 @@ export function HelpOssGraph() {
|
|||
<IconExecute className='inline-icon icon-green' /> Активировать операцию
|
||||
</li>
|
||||
<li>
|
||||
<IconReference className='inline-icon icon-green' /> Создать ссылку
|
||||
<IconReference className='inline-icon icon-green' /> Создать реплику
|
||||
</li>
|
||||
<li>
|
||||
<IconClone className='inline-icon icon-green' /> Клонировать КС и загрузить
|
||||
|
@ -155,7 +155,7 @@ export function HelpOssGraph() {
|
|||
<IconRSForm className='inline-icon' /> Открыть привязанную КС
|
||||
</li>
|
||||
<li>
|
||||
<IconReference className='inline-icon' /> Выделить отсылаемую операцию
|
||||
<IconReference className='inline-icon' /> Выделить оригинал реплики
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -33,7 +33,7 @@ export function HelpRSGraphTerm() {
|
|||
<div className='flex flex-col'>
|
||||
<h1>Граф термов</h1>
|
||||
<div className='flex flex-col sm:flex-row'>
|
||||
<div className='sm:w-56'>
|
||||
<div className='sm:w-60'>
|
||||
<h2>Настройка графа</h2>
|
||||
<ul>
|
||||
<li>Цвет – покраска узлов</li>
|
||||
|
@ -51,11 +51,11 @@ export function HelpRSGraphTerm() {
|
|||
|
||||
<Divider vertical margins='mx-3 mt-3' className='hidden sm:block' />
|
||||
|
||||
<div className='sm:w-84'>
|
||||
<div className='sm:w-80'>
|
||||
<h2>Изменение узлов</h2>
|
||||
<ul>
|
||||
<li>Клик на узел – выделение</li>
|
||||
<li>Левый клик – выбор фокус-конституенты</li>
|
||||
<li>Левый клик – фокус-конституента</li>
|
||||
<li>
|
||||
<IconReset className='inline-icon' /> Esc – сбросить выделение
|
||||
</li>
|
||||
|
@ -75,7 +75,7 @@ export function HelpRSGraphTerm() {
|
|||
<Divider margins='my-3' className='hidden sm:block' />
|
||||
|
||||
<div className='flex flex-col-reverse mb-3 sm:flex-row'>
|
||||
<div className='sm:w-56'>
|
||||
<div className='sm:w-60'>
|
||||
<h2>Общие</h2>
|
||||
<ul>
|
||||
<li>
|
||||
|
|
|
@ -9,12 +9,12 @@ import {
|
|||
type ICloneSchemaDTO,
|
||||
type IConstituentaReference,
|
||||
type ICreateBlockDTO,
|
||||
type ICreateReferenceDTO,
|
||||
type ICreateReplicaDTO,
|
||||
type ICreateSchemaDTO,
|
||||
type ICreateSynthesisDTO,
|
||||
type IDeleteBlockDTO,
|
||||
type IDeleteOperationDTO,
|
||||
type IDeleteReferenceDTO,
|
||||
type IDeleteReplicaDTO,
|
||||
type IImportSchemaDTO,
|
||||
type IInputCreatedResponse,
|
||||
type IMoveItemsDTO,
|
||||
|
@ -89,10 +89,10 @@ export const ossApi = {
|
|||
}
|
||||
}),
|
||||
|
||||
createReference: ({ itemID, data }: { itemID: number; data: ICreateReferenceDTO }) =>
|
||||
axiosPost<ICreateReferenceDTO, IOperationCreatedResponse>({
|
||||
createReplica: ({ itemID, data }: { itemID: number; data: ICreateReplicaDTO }) =>
|
||||
axiosPost<ICreateReplicaDTO, IOperationCreatedResponse>({
|
||||
schema: schemaOperationCreatedResponse,
|
||||
endpoint: `/api/oss/${itemID}/create-reference`,
|
||||
endpoint: `/api/oss/${itemID}/create-replica`,
|
||||
request: {
|
||||
data: data,
|
||||
successMessage: response => {
|
||||
|
@ -101,10 +101,10 @@ export const ossApi = {
|
|||
}
|
||||
}
|
||||
}),
|
||||
deleteReference: ({ itemID, data }: { itemID: number; data: IDeleteReferenceDTO; beforeUpdate?: () => void }) =>
|
||||
axiosPatch<IDeleteReferenceDTO, IOperationSchemaDTO>({
|
||||
deleteReplica: ({ itemID, data }: { itemID: number; data: IDeleteReplicaDTO; beforeUpdate?: () => void }) =>
|
||||
axiosPatch<IDeleteReplicaDTO, IOperationSchemaDTO>({
|
||||
schema: schemaOperationSchema,
|
||||
endpoint: `/api/oss/${itemID}/delete-reference`,
|
||||
endpoint: `/api/oss/${itemID}/delete-replica`,
|
||||
request: {
|
||||
data: data,
|
||||
successMessage: infoMsg.operationDestroyed
|
||||
|
|
|
@ -82,8 +82,8 @@ export class OssLoader {
|
|||
this.graph.addEdge(argument.argument, argument.operation);
|
||||
this.extendedGraph.addEdge(argument.argument, argument.operation);
|
||||
});
|
||||
this.oss.references.forEach(reference => {
|
||||
this.extendedGraph.addEdge(reference.target, reference.reference);
|
||||
this.oss.replicas.forEach(reference => {
|
||||
this.extendedGraph.addEdge(reference.original, reference.replica);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -109,18 +109,18 @@ export class OssLoader {
|
|||
.filter(item => item.operation === operationID)
|
||||
.map(item => item.argument);
|
||||
break;
|
||||
case OperationType.REFERENCE:
|
||||
const ref = this.oss.references.find(item => item.reference === operationID);
|
||||
const target = !!ref ? this.operationByID.get(ref.target) : null;
|
||||
if (!target || !ref) {
|
||||
throw new Error(`Reference ${operationID} not found`);
|
||||
case OperationType.REPLICA:
|
||||
const replication = this.oss.replicas.find(item => item.replica === operationID);
|
||||
const original = !!replication ? this.operationByID.get(replication.original) : null;
|
||||
if (!original || !replication) {
|
||||
throw new Error(`Replica ${operationID} not found`);
|
||||
}
|
||||
const refCount = (referenceCounts.get(target.id) ?? 0) + 1;
|
||||
referenceCounts.set(target.id, refCount);
|
||||
operation.target = ref.target;
|
||||
operation.alias = `[${refCount}] ${target.alias}`;
|
||||
operation.title = target.title;
|
||||
operation.description = target.description;
|
||||
const refCount = (referenceCounts.get(original.id) ?? 0) + 1;
|
||||
referenceCounts.set(original.id, refCount);
|
||||
operation.target = replication.original;
|
||||
operation.alias = `[${refCount}] ${original.alias}`;
|
||||
operation.title = original.title;
|
||||
operation.description = original.description;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
@ -160,7 +160,7 @@ export class OssLoader {
|
|||
item => !!item.result && (item.operation_type !== OperationType.INPUT || !item.is_import)
|
||||
).length,
|
||||
count_block: this.oss.blocks.length,
|
||||
count_references: this.oss.references.length
|
||||
count_references: this.oss.replicas.length
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import { errorMsg } from '@/utils/labels';
|
|||
export const OperationType = {
|
||||
INPUT: 'input',
|
||||
SYNTHESIS: 'synthesis',
|
||||
REFERENCE: 'reference'
|
||||
REPLICA: 'replica'
|
||||
} as const;
|
||||
export type OperationType = (typeof OperationType)[keyof typeof OperationType];
|
||||
|
||||
|
@ -49,7 +49,7 @@ export type IMoveItemsDTO = z.infer<typeof schemaMoveItems>;
|
|||
|
||||
/** Represents {@link IOperation} data, used in Create action. */
|
||||
export type ICreateSchemaDTO = z.infer<typeof schemaCreateSchema>;
|
||||
export type ICreateReferenceDTO = z.infer<typeof schemaCreateReference>;
|
||||
export type ICreateReplicaDTO = z.infer<typeof schemaCreateReplica>;
|
||||
export type ICreateSynthesisDTO = z.infer<typeof schemaCreateSynthesis>;
|
||||
export type IImportSchemaDTO = z.infer<typeof schemaImportSchema>;
|
||||
export type ICloneSchemaDTO = z.infer<typeof schemaCloneSchema>;
|
||||
|
@ -64,7 +64,7 @@ export type IUpdateOperationDTO = z.infer<typeof schemaUpdateOperation>;
|
|||
export type IDeleteOperationDTO = z.infer<typeof schemaDeleteOperation>;
|
||||
|
||||
/** Represents {@link IOperation} reference type data, used in Delete action. */
|
||||
export type IDeleteReferenceDTO = z.infer<typeof schemaDeleteReference>;
|
||||
export type IDeleteReplicaDTO = z.infer<typeof schemaDeleteReplica>;
|
||||
|
||||
/** Represents target {@link IOperation}. */
|
||||
export interface ITargetOperation {
|
||||
|
@ -124,9 +124,9 @@ export const schemaBlock = z.strictObject({
|
|||
parent: z.number().nullable()
|
||||
});
|
||||
|
||||
const schemaReference = z.strictObject({
|
||||
target: z.number(),
|
||||
reference: z.number()
|
||||
const schemaReplica = z.strictObject({
|
||||
original: z.number(),
|
||||
replica: z.number()
|
||||
});
|
||||
|
||||
export const schemaPosition = z.strictObject({
|
||||
|
@ -158,7 +158,7 @@ export const schemaOperationSchema = schemaLibraryItem.extend({
|
|||
editors: z.number().array(),
|
||||
operations: z.array(schemaOperation),
|
||||
blocks: z.array(schemaBlock),
|
||||
references: z.array(schemaReference),
|
||||
replicas: z.array(schemaReplica),
|
||||
layout: schemaOssLayout,
|
||||
arguments: z
|
||||
.object({
|
||||
|
@ -199,7 +199,7 @@ export const schemaCreateSchema = z.strictObject({
|
|||
position: schemaPosition
|
||||
});
|
||||
|
||||
export const schemaCreateReference = z.strictObject({
|
||||
export const schemaCreateReplica = z.strictObject({
|
||||
target: z.number(),
|
||||
layout: schemaOssLayout,
|
||||
position: schemaPosition
|
||||
|
@ -247,7 +247,7 @@ export const schemaDeleteOperation = z.strictObject({
|
|||
delete_schema: z.boolean()
|
||||
});
|
||||
|
||||
export const schemaDeleteReference = z.strictObject({
|
||||
export const schemaDeleteReplica = z.strictObject({
|
||||
target: z.number(),
|
||||
layout: schemaOssLayout,
|
||||
keep_constituents: z.boolean(),
|
||||
|
|
|
@ -5,14 +5,14 @@ import { useUpdateTimestamp } from '@/features/library/backend/use-update-timest
|
|||
import { KEYS } from '@/backend/configuration';
|
||||
|
||||
import { ossApi } from './api';
|
||||
import { type ICreateReferenceDTO } from './types';
|
||||
import { type ICreateReplicaDTO } from './types';
|
||||
|
||||
export const useCreateReference = () => {
|
||||
const client = useQueryClient();
|
||||
const { updateTimestamp } = useUpdateTimestamp();
|
||||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, ossApi.baseKey, 'create-reference'],
|
||||
mutationFn: ossApi.createReference,
|
||||
mutationKey: [KEYS.global_mutation, ossApi.baseKey, 'create-replica'],
|
||||
mutationFn: ossApi.createReplica,
|
||||
onSuccess: data => {
|
||||
updateTimestamp(data.oss.id, data.oss.time_update);
|
||||
client.setQueryData(ossApi.getOssQueryOptions({ itemID: data.oss.id }).queryKey, data.oss);
|
||||
|
@ -20,6 +20,6 @@ export const useCreateReference = () => {
|
|||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
createReference: (data: { itemID: number; data: ICreateReferenceDTO }) => mutation.mutateAsync(data)
|
||||
createReplica: (data: { itemID: number; data: ICreateReplicaDTO }) => mutation.mutateAsync(data)
|
||||
};
|
||||
};
|
|
@ -6,14 +6,14 @@ import { KEYS } from '@/backend/configuration';
|
|||
import { PARAMETER } from '@/utils/constants';
|
||||
|
||||
import { ossApi } from './api';
|
||||
import { type IDeleteReferenceDTO } from './types';
|
||||
import { type IDeleteReplicaDTO } from './types';
|
||||
|
||||
export const useDeleteReference = () => {
|
||||
export const useDeleteReplica = () => {
|
||||
const client = useQueryClient();
|
||||
const { updateTimestamp } = useUpdateTimestamp();
|
||||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, ossApi.baseKey, 'delete-reference'],
|
||||
mutationFn: ossApi.deleteReference,
|
||||
mutationKey: [KEYS.global_mutation, ossApi.baseKey, 'delete-replica'],
|
||||
mutationFn: ossApi.deleteReplica,
|
||||
onSuccess: async (data, variables) => {
|
||||
if (variables.beforeUpdate) {
|
||||
variables.beforeUpdate();
|
||||
|
@ -29,7 +29,7 @@ export const useDeleteReference = () => {
|
|||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
deleteReference: (data: { itemID: number; data: IDeleteReferenceDTO; beforeUpdate?: () => void }) => {
|
||||
deleteReplica: (data: { itemID: number; data: IDeleteReplicaDTO; beforeUpdate?: () => void }) => {
|
||||
mutation.mutate(data);
|
||||
}
|
||||
};
|
|
@ -41,7 +41,7 @@ export function OssStats({ className, stats }: OssStatsProps) {
|
|||
/>
|
||||
<ValueStats
|
||||
id='count_references'
|
||||
title='Синтез'
|
||||
title='Реплика'
|
||||
icon={<IconReference size='1.25rem' />}
|
||||
value={stats.count_references}
|
||||
/>
|
||||
|
|
|
@ -20,7 +20,7 @@ export function TabArguments() {
|
|||
} = useFormContext<ICreateSynthesisDTO>();
|
||||
const inputs = useWatch({ control, name: 'arguments' });
|
||||
|
||||
const references = manager.oss.references.filter(item => inputs.includes(item.target)).map(item => item.reference);
|
||||
const references = manager.oss.replicas.filter(item => inputs.includes(item.original)).map(item => item.replica);
|
||||
const filtered = manager.oss.operations.filter(item => !references.includes(item.id));
|
||||
|
||||
return (
|
||||
|
|
|
@ -9,23 +9,23 @@ import { Checkbox, TextInput } from '@/components/input';
|
|||
import { ModalForm } from '@/components/modal';
|
||||
import { useDialogsStore } from '@/stores/dialogs';
|
||||
|
||||
import { type IDeleteReferenceDTO, type IOssLayout, schemaDeleteReference } from '../backend/types';
|
||||
import { useDeleteReference } from '../backend/use-delete-reference';
|
||||
import { type IOperationReference, type IOperationSchema } from '../models/oss';
|
||||
import { type IDeleteReplicaDTO, type IOssLayout, schemaDeleteReplica } from '../backend/types';
|
||||
import { useDeleteReplica } from '../backend/use-delete-replica';
|
||||
import { type IOperationReplica, type IOperationSchema } from '../models/oss';
|
||||
|
||||
export interface DlgDeleteReferenceProps {
|
||||
export interface DlgDeleteReplicaProps {
|
||||
oss: IOperationSchema;
|
||||
target: IOperationReference;
|
||||
target: IOperationReplica;
|
||||
layout: IOssLayout;
|
||||
beforeDelete?: () => void;
|
||||
}
|
||||
|
||||
export function DlgDeleteReference() {
|
||||
const { oss, target, layout, beforeDelete } = useDialogsStore(state => state.props as DlgDeleteReferenceProps);
|
||||
const { deleteReference } = useDeleteReference();
|
||||
export function DlgDeleteReplica() {
|
||||
const { oss, target, layout, beforeDelete } = useDialogsStore(state => state.props as DlgDeleteReplicaProps);
|
||||
const { deleteReplica: deleteReference } = useDeleteReplica();
|
||||
|
||||
const { handleSubmit, control } = useForm<IDeleteReferenceDTO>({
|
||||
resolver: zodResolver(schemaDeleteReference),
|
||||
const { handleSubmit, control } = useForm<IDeleteReplicaDTO>({
|
||||
resolver: zodResolver(schemaDeleteReplica),
|
||||
defaultValues: {
|
||||
target: target.id,
|
||||
layout: layout,
|
||||
|
@ -35,14 +35,14 @@ export function DlgDeleteReference() {
|
|||
});
|
||||
const keep_connections = useWatch({ control, name: 'keep_connections' });
|
||||
|
||||
function onSubmit(data: IDeleteReferenceDTO) {
|
||||
function onSubmit(data: IDeleteReplicaDTO) {
|
||||
return deleteReference({ itemID: oss.id, data: data, beforeUpdate: beforeDelete });
|
||||
}
|
||||
|
||||
return (
|
||||
<ModalForm
|
||||
overflowVisible
|
||||
header='Удаление операции'
|
||||
header='Удаление реплики'
|
||||
submitText='Подтвердить удаление'
|
||||
onSubmit={event => void handleSubmit(onSubmit)(event)}
|
||||
className='w-140 pb-3 px-6 cc-column select-none'
|
||||
|
@ -55,7 +55,7 @@ export function DlgDeleteReference() {
|
|||
render={({ field }) => (
|
||||
<Checkbox
|
||||
label='Переадресовать связи на оригинал'
|
||||
titleHtml='Связи аргументов будут перенаправлены на оригинал ссылки'
|
||||
titleHtml='Связи аргументов будут перенаправлены на оригинал реплики'
|
||||
value={field.value}
|
||||
onChange={field.onChange}
|
||||
disabled={target.result === null}
|
|
@ -15,9 +15,9 @@ export function TabArguments() {
|
|||
const { manager, target } = useDialogsStore(state => state.props as DlgEditOperationProps);
|
||||
const args = useWatch({ control, name: 'arguments' });
|
||||
|
||||
const references = manager.oss.references
|
||||
.filter(item => args.includes(item.target) || item.target === target.id)
|
||||
.map(item => item.reference);
|
||||
const references = manager.oss.replicas
|
||||
.filter(item => args.includes(item.original) || item.original === target.id)
|
||||
.map(item => item.replica);
|
||||
const potentialCycle = [target.id, ...references, ...manager.oss.graph.expandAllOutputs([target.id])];
|
||||
const filtered = manager.oss.operations.filter(item => !potentialCycle.includes(item.id));
|
||||
|
||||
|
|
|
@ -12,13 +12,13 @@ import {
|
|||
const labelOperationTypeRecord: Record<OperationType, string> = {
|
||||
[OperationType.INPUT]: 'Загрузка',
|
||||
[OperationType.SYNTHESIS]: 'Синтез',
|
||||
[OperationType.REFERENCE]: 'Ссылка'
|
||||
[OperationType.REPLICA]: 'Репликация'
|
||||
};
|
||||
|
||||
const describeOperationTypeRecord: Record<OperationType, string> = {
|
||||
[OperationType.INPUT]: 'Загрузка концептуальной схемы в ОСС',
|
||||
[OperationType.SYNTHESIS]: 'Синтез концептуальных схем',
|
||||
[OperationType.REFERENCE]: 'Создание ссылки на результат операции'
|
||||
[OperationType.REPLICA]: 'Создание ссылки на результат операции'
|
||||
};
|
||||
|
||||
/** Retrieves label for {@link OperationType}. */
|
||||
|
|
|
@ -43,9 +43,9 @@ export interface IOperationInput extends IOperationBase {
|
|||
is_import: boolean;
|
||||
}
|
||||
|
||||
/** Represents Reference Operation. */
|
||||
export interface IOperationReference extends IOperationBase {
|
||||
operation_type: typeof OperationType.REFERENCE;
|
||||
/** Represents Replica Operation. */
|
||||
export interface IOperationReplica extends IOperationBase {
|
||||
operation_type: typeof OperationType.REPLICA;
|
||||
target: number;
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ export interface IOperationSynthesis extends IOperationBase {
|
|||
}
|
||||
|
||||
/** Represents Operation. */
|
||||
export type IOperation = IOperationInput | IOperationReference | IOperationSynthesis;
|
||||
export type IOperation = IOperationInput | IOperationReplica | IOperationSynthesis;
|
||||
|
||||
/** Represents Block. */
|
||||
export interface IBlock extends IOssNode, IBlockDTO {
|
||||
|
|
|
@ -4,7 +4,7 @@ import { toast } from 'react-toastify';
|
|||
|
||||
import { useLibrary } from '@/features/library/backend/use-library';
|
||||
import { useCloneSchema } from '@/features/oss/backend/use-clone-schema';
|
||||
import { useCreateReference } from '@/features/oss/backend/use-create-reference';
|
||||
import { useCreateReference } from '@/features/oss/backend/use-create-replica';
|
||||
|
||||
import { DropdownButton } from '@/components/dropdown';
|
||||
import {
|
||||
|
@ -46,7 +46,7 @@ export function MenuOperation({ operation, onHide }: MenuOperationProps) {
|
|||
const { createInput: inputCreate } = useCreateInput();
|
||||
const { executeOperation: operationExecute } = useExecuteOperation();
|
||||
const { cloneSchema } = useCloneSchema();
|
||||
const { createReference } = useCreateReference();
|
||||
const { createReplica: createReference } = useCreateReference();
|
||||
|
||||
const showEditInput = useDialogsStore(state => state.showChangeInputSchema);
|
||||
const showRelocateConstituents = useDialogsStore(state => state.showRelocateConstituents);
|
||||
|
@ -96,7 +96,7 @@ export function MenuOperation({ operation, onHide }: MenuOperationProps) {
|
|||
}
|
||||
|
||||
function handleEditOperation() {
|
||||
if (!operation || operation.operation_type === OperationType.REFERENCE) {
|
||||
if (!operation || operation.operation_type === OperationType.REPLICA) {
|
||||
return;
|
||||
}
|
||||
onHide();
|
||||
|
@ -112,7 +112,7 @@ export function MenuOperation({ operation, onHide }: MenuOperationProps) {
|
|||
}
|
||||
onHide();
|
||||
switch (operation.operation_type) {
|
||||
case OperationType.REFERENCE:
|
||||
case OperationType.REPLICA:
|
||||
showDeleteReference({
|
||||
oss: schema,
|
||||
target: operation,
|
||||
|
@ -211,7 +211,7 @@ export function MenuOperation({ operation, onHide }: MenuOperationProps) {
|
|||
|
||||
function handleSelectTarget() {
|
||||
onHide();
|
||||
if (operation.operation_type !== OperationType.REFERENCE) {
|
||||
if (operation.operation_type !== OperationType.REPLICA) {
|
||||
return;
|
||||
}
|
||||
setSelected([`o${operation.target}`]);
|
||||
|
@ -219,7 +219,7 @@ export function MenuOperation({ operation, onHide }: MenuOperationProps) {
|
|||
|
||||
return (
|
||||
<>
|
||||
{operation.operation_type !== OperationType.REFERENCE ? (
|
||||
{operation.operation_type !== OperationType.REPLICA ? (
|
||||
<DropdownButton
|
||||
text='Редактировать'
|
||||
title='Редактировать операцию'
|
||||
|
@ -282,7 +282,7 @@ export function MenuOperation({ operation, onHide }: MenuOperationProps) {
|
|||
/>
|
||||
) : null}
|
||||
|
||||
{isMutable && operation.result && operation.operation_type !== OperationType.REFERENCE ? (
|
||||
{isMutable && operation.result && operation.operation_type !== OperationType.REPLICA ? (
|
||||
<DropdownButton
|
||||
text='Конституенты'
|
||||
titleHtml='Перенос конституент</br>между схемами'
|
||||
|
@ -293,17 +293,17 @@ export function MenuOperation({ operation, onHide }: MenuOperationProps) {
|
|||
/>
|
||||
) : null}
|
||||
|
||||
{isMutable && operation.operation_type !== OperationType.REFERENCE ? (
|
||||
{isMutable && operation.operation_type !== OperationType.REPLICA ? (
|
||||
<DropdownButton
|
||||
text='Создать ссылку'
|
||||
title='Создать ссылку на результат операции'
|
||||
text='Создать реплику'
|
||||
title='Создать реплику результата операции'
|
||||
icon={<IconReference size='1rem' className='icon-green' />}
|
||||
onClick={handleCreateReference}
|
||||
disabled={isProcessing}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{isMutable && operation.operation_type !== OperationType.REFERENCE ? (
|
||||
{isMutable && operation.operation_type !== OperationType.REPLICA ? (
|
||||
<DropdownButton
|
||||
text='Клонировать'
|
||||
title='Создать и загрузить копию концептуальной схемы'
|
||||
|
|
|
@ -38,7 +38,7 @@ export function NodeCore({ node }: NodeCoreProps) {
|
|||
className={cn(
|
||||
'cc-node-operation h-[40px] w-[150px]',
|
||||
'relative flex items-center justify-center p-[2px]',
|
||||
opType === OperationType.REFERENCE && 'border-dashed',
|
||||
opType === OperationType.REPLICA && 'border-dashed',
|
||||
isChild && 'border-accent-orange'
|
||||
)}
|
||||
>
|
||||
|
|
|
@ -2,12 +2,12 @@ import { type NodeTypes } from 'reactflow';
|
|||
|
||||
import { BlockNode } from './block-node';
|
||||
import { InputNode } from './input-node';
|
||||
import { ReferenceNode } from './reference-node';
|
||||
import { ReplicaNode } from './replica-node';
|
||||
import { SynthesisNode } from './synthesis-node';
|
||||
|
||||
export const OssNodeTypes: NodeTypes = {
|
||||
input: InputNode,
|
||||
synthesis: SynthesisNode,
|
||||
reference: ReferenceNode,
|
||||
replica: ReplicaNode,
|
||||
block: BlockNode
|
||||
} as const;
|
||||
|
|
|
@ -4,7 +4,7 @@ import { type OperationInternalNode } from '../../../../models/oss-layout';
|
|||
|
||||
import { NodeCore } from './node-core';
|
||||
|
||||
export function ReferenceNode(node: OperationInternalNode) {
|
||||
export function ReplicaNode(node: OperationInternalNode) {
|
||||
return (
|
||||
<>
|
||||
<NodeCore node={node} />
|
|
@ -161,7 +161,7 @@ export function OssFlow() {
|
|||
return;
|
||||
}
|
||||
switch (item.operation_type) {
|
||||
case OperationType.REFERENCE:
|
||||
case OperationType.REPLICA:
|
||||
showDeleteReference({
|
||||
oss: schema,
|
||||
target: item,
|
||||
|
|
|
@ -20,7 +20,7 @@ export function BlockStats({ target, oss }: BlockStatsProps) {
|
|||
item => !!item.result && (item.operation_type !== OperationType.INPUT || !item.is_import)
|
||||
).length,
|
||||
count_block: contents.length - operations.length,
|
||||
count_references: operations.filter(item => item.operation_type === OperationType.REFERENCE).length
|
||||
count_references: operations.filter(item => item.operation_type === OperationType.REPLICA).length
|
||||
};
|
||||
|
||||
return <OssStats stats={blockStats} className='pr-3' />;
|
||||
|
|
|
@ -109,7 +109,7 @@ export const OssEditState = ({ itemID, children }: React.PropsWithChildren<OssEd
|
|||
}
|
||||
|
||||
function canDeleteOperation(target: IOperation) {
|
||||
if (target.operation_type === OperationType.INPUT || target.operation_type === OperationType.REFERENCE) {
|
||||
if (target.operation_type === OperationType.INPUT || target.operation_type === OperationType.REPLICA) {
|
||||
return true;
|
||||
}
|
||||
return schema.graph.expandOutputs([target.id]).length === 0;
|
||||
|
|
|
@ -11,7 +11,7 @@ import { type DlgCreateBlockProps } from '@/features/oss/dialogs/dlg-create-bloc
|
|||
import { type DlgCreateSchemaProps } from '@/features/oss/dialogs/dlg-create-schema';
|
||||
import { type DlgCreateSynthesisProps } from '@/features/oss/dialogs/dlg-create-synthesis/dlg-create-synthesis';
|
||||
import { type DlgDeleteOperationProps } from '@/features/oss/dialogs/dlg-delete-operation';
|
||||
import { type DlgDeleteReferenceProps } from '@/features/oss/dialogs/dlg-delete-reference';
|
||||
import { type DlgDeleteReplicaProps } from '@/features/oss/dialogs/dlg-delete-replica';
|
||||
import { type DlgEditBlockProps } from '@/features/oss/dialogs/dlg-edit-block';
|
||||
import { type DlgEditOperationProps } from '@/features/oss/dialogs/dlg-edit-operation/dlg-edit-operation';
|
||||
import { type DlgImportSchemaProps } from '@/features/oss/dialogs/dlg-import-schema';
|
||||
|
@ -106,7 +106,7 @@ interface DialogsStore {
|
|||
showCloneLibraryItem: (props: DlgCloneLibraryItemProps) => void;
|
||||
showCreateVersion: (props: DlgCreateVersionProps) => void;
|
||||
showDeleteOperation: (props: DlgDeleteOperationProps) => void;
|
||||
showDeleteReference: (props: DlgDeleteReferenceProps) => void;
|
||||
showDeleteReference: (props: DlgDeleteReplicaProps) => void;
|
||||
showGraphParams: () => void;
|
||||
showOssOptions: () => void;
|
||||
showRelocateConstituents: (props: DlgRelocateConstituentsProps) => void;
|
||||
|
|
Loading…
Reference in New Issue
Block a user