Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CaosDB WebUI Entity Service
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB WebUI Entity Service
Commits
b24b3945
Commit
b24b3945
authored
3 years ago
by
Florian Spreckelsen
Browse files
Options
Downloads
Patches
Plain Diff
DRAFT: Begin implementation of properties
parent
0e9ba0de
No related branches found
No related tags found
1 merge request
!1
ENH: Add property and entity classes
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Property.js
+94
-0
94 additions, 0 deletions
src/Property.js
src/index.js
+7
-1
7 additions, 1 deletion
src/index.js
with
101 additions
and
1 deletion
src/Property.js
0 → 100644
+
94
−
0
View file @
b24b3945
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2021 Florian Spreckelsen <f.spreckelsen@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
import
{
api
}
from
"
./EntityApi
"
;
function
_getScalarValue
(
value
)
{
const
valueCases
=
api
.
v1
.
ScalarValue
.
ScalarValueCase
;
switch
(
value
.
getScalarValueCase
())
{
case
valueCases
.
SCALAR_VALUE_NOT_SET
:
return
undefined
;
case
valueCases
.
INTEGER_VALUE
:
return
value
.
getIntegerValue
();
case
valueCases
.
DOUBLE_VALUE
:
return
value
.
getDoubleValue
();
case
valueCases
.
BOOLEAN_VALUE
:
return
value
.
getBooleanValue
();
case
valueCases
.
STRING_VALUE
:
return
value
.
getStringValue
();
default
:
throw
`Unkown value type
${
value
.
getScalarValueCase
()}
.`
;
}
}
function
_getListValue
(
listDataType
,
values
)
{
const
listCases
=
api
.
v1
.
ListDataType
.
ListDataTypeCase
;
switch
(
listDataType
.
getListDataTypeCase
())
{
case
listCases
.
LIST_DATA_TYPE_NOT_SET
:
return
undefined
;
case
listCases
.
ATOMIC_DATA_TYPE
:
return
values
.
map
(
value
=>
_getScalarValue
(
value
));
case
listCases
.
REFERENCE_DATA_TYPE
:
return
values
.
map
(
value
=>
_getScalarValue
(
value
));
default
:
throe
`Unknown list data type
${
listDataType
.
getListDataTypeCase
()}
.`
}
}
export
class
Property
{
constructor
(
protoProperty
)
{
this
.
wrappedProperty
=
protoProperty
;
}
getName
()
{
return
this
.
wrappedProperty
.
getName
();
}
getId
()
{
return
this
.
wrappedProperty
.
getId
();
}
getValue
()
{
const
wrappedValue
=
this
.
wrappedProperty
.
getValue
();
if
(
value
===
undefined
)
{
// Empty values are undefined regardless of data type
return
undefined
;
}
const
wrappedDataType
=
this
.
wrappedProperty
.
getDataType
();
const
dtypeCases
=
api
.
v1
.
DataType
.
DataTypeCase
;
switch
(
wrappedDataType
.
getDataTypeCase
())
{
case
dtypeCases
.
DATA_TYPE_NOT_SET
:
return
undefined
;
case
dtypeCases
.
ATOMIC_DATA_TYPE
:
return
_getScalarValue
(
wrappedValue
.
getScalarValue
());
case
dtypeCases
.
LIST_DATA_TYPE
:
return
_getListValue
(
wrappedDataType
.
getListDataTypeCase
(),
wrappedValue
.
getListValues
().
getValuesList
());
case
dtypeCases
.
REFERENCE_DATA_TYPE
:
return
_getScalarValue
(
wrappedValue
.
getScalarValue
());
default
:
throw
`Unkown data type
${
wrappedDataType
.
getDataTypeCase
()}
.`
;
}
}
}
This diff is collapsed.
Click to expand it.
src/index.js
+
7
−
1
View file @
b24b3945
...
@@ -20,6 +20,12 @@
...
@@ -20,6 +20,12 @@
*
*
* ** end header
* ** end header
*/
*/
export
{
Property
}
from
"
./Property
"
;
export
{
export
{
TransactionService
TransactionService
}
from
"
./TransactionService
"
;
}
from
"
./TransactionService
"
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment