@@ -40,6 +40,8 @@ import ActionType, {
4040import Resource , { ResourceData } from "../model/Resource" ;
4141import RdfsResource , {
4242 CONTEXT as RDFS_RESOURCE_CONTEXT ,
43+ RdfProperty ,
44+ RdfPropertyData ,
4345 RdfsResourceData ,
4446} from "../model/RdfsResource" ;
4547import TermItState from "../model/TermItState" ;
@@ -518,6 +520,7 @@ export function loadAllTerms(
518520 {
519521 searchString : fetchOptions . searchString ,
520522 includeTerms : fetchOptions . includeTerms ,
523+ flat : fetchOptions . flatList ,
521524 namespace,
522525 } ,
523526 fetchOptions
@@ -535,6 +538,7 @@ export function loadTerms(
535538 searchString : fetchOptions . searchString ,
536539 includeImported : fetchOptions . includeImported ,
537540 includeTerms : fetchOptions . includeTerms ,
541+ flat : fetchOptions . flatList ,
538542 namespace : vocabularyIri . namespace ,
539543 } ,
540544 fetchOptions
@@ -552,10 +556,10 @@ export function genericLoadTerms(
552556 dispatch ( asyncActionRequest ( action , true ) ) ;
553557 let url = `${ getApiPrefix ( getState ( ) ) } ${ prefix } /terms` ;
554558 if ( fetchOptions . optionID ) {
555- const parentIri = VocabularyUtils . create ( fetchOptions . optionID ) ;
559+ const parentIri = VocabularyUtils . create ( fetchOptions . optionID as string ) ;
556560 url = `${ getApiPrefix ( getState ( ) ) } /terms/${ parentIri . fragment } /subterms` ;
557561 target . namespace = parentIri . namespace ;
558- } else if ( ! fetchOptions . searchString ) {
562+ } else if ( ! fetchOptions . searchString && ! fetchOptions . flatList ) {
559563 url += "/roots" ;
560564 }
561565 return Ajax . get (
@@ -651,6 +655,7 @@ export function loadTermByIri(
651655 } ) ;
652656 } ;
653657}
658+
654659export function loadTypes ( ) {
655660 const action = {
656661 type : ActionType . LOAD_TYPES ,
@@ -1058,25 +1063,34 @@ export function getProperties() {
10581063 const action = {
10591064 type : ActionType . GET_PROPERTIES ,
10601065 } ;
1066+ return getPropertiesImpl < RdfsResourceData , RdfsResource > (
1067+ action ,
1068+ "/data/properties" ,
1069+ ( d ) => new RdfsResource ( d ) ,
1070+ ( state ) => state . properties
1071+ ) ;
1072+ }
1073+
1074+ function getPropertiesImpl < T extends RdfsResourceData , E extends RdfsResource > (
1075+ action : Action ,
1076+ endpoint : string ,
1077+ mapper : ( data : T ) => E ,
1078+ selector : ( state : TermItState ) => Array < E >
1079+ ) {
10611080 return ( dispatch : ThunkDispatch , getState : ( ) => TermItState ) => {
1062- if ( getState ( ) . properties . length > 0 ) {
1081+ if ( selector ( getState ( ) ) . length > 0 ) {
10631082 return ;
10641083 }
10651084 dispatch ( asyncActionRequest ( action , true ) ) ;
1066- return Ajax . get ( Constants . API_PREFIX + "/data/properties" )
1085+ return Ajax . get ( Constants . API_PREFIX + endpoint )
10671086 . then ( ( data : object [ ] ) =>
1068- JsonLdUtils . compactAndResolveReferencesAsArray < RdfsResourceData > (
1087+ JsonLdUtils . compactAndResolveReferencesAsArray < T > (
10691088 data ,
10701089 RDFS_RESOURCE_CONTEXT
10711090 )
10721091 )
1073- . then ( ( data : RdfsResourceData [ ] ) =>
1074- dispatch (
1075- asyncActionSuccessWithPayload (
1076- action ,
1077- data . map ( ( d ) => new RdfsResource ( d ) )
1078- )
1079- )
1092+ . then ( ( data : T [ ] ) =>
1093+ dispatch ( asyncActionSuccessWithPayload ( action , data . map ( mapper ) ) )
10801094 )
10811095 . catch ( ( error : ErrorData ) => dispatch ( asyncActionFailure ( action , error ) ) ) ;
10821096 } ;
@@ -1086,13 +1100,76 @@ export function createProperty(property: RdfsResource) {
10861100 const action = {
10871101 type : ActionType . CREATE_PROPERTY ,
10881102 } ;
1103+ return createPropertyImpl ( property , action , "/data/properties" ) ;
1104+ }
1105+
1106+ function createPropertyImpl (
1107+ property : { toJsonLd : ( ) => object } ,
1108+ action : Action ,
1109+ endpoint : string
1110+ ) {
10891111 return ( dispatch : ThunkDispatch ) => {
10901112 dispatch ( asyncActionRequest ( action , true ) ) ;
10911113 return Ajax . post (
1092- Constants . API_PREFIX + "/data/properties" ,
1114+ Constants . API_PREFIX + endpoint ,
10931115 content ( property . toJsonLd ( ) )
10941116 )
1095- . then ( ( ) => dispatch ( asyncActionSuccess ( action ) ) )
1117+ . then ( ( ) => {
1118+ dispatch ( asyncActionSuccess ( action ) ) ;
1119+ dispatch (
1120+ publishMessage (
1121+ new Message (
1122+ { messageId : "properties.edit.new.success" } ,
1123+ MessageType . SUCCESS
1124+ )
1125+ )
1126+ ) ;
1127+ } )
1128+ . catch ( ( error : ErrorData ) => dispatch ( asyncActionFailure ( action , error ) ) ) ;
1129+ } ;
1130+ }
1131+
1132+ export function getCustomAttributes ( ) {
1133+ return getPropertiesImpl < RdfPropertyData , RdfProperty > (
1134+ { type : ActionType . GET_CUSTOM_ATTRIBUTES } ,
1135+ "/data/custom-attributes" ,
1136+ ( d ) => new RdfProperty ( d ) ,
1137+ ( ) => [ ]
1138+ ) ;
1139+ }
1140+
1141+ export function createCustomAttribute ( attribute : RdfProperty ) {
1142+ return createPropertyImpl (
1143+ attribute ,
1144+ { type : ActionType . CREATE_CUSTOM_ATTRIBUTE } ,
1145+ "/data/custom-attributes"
1146+ ) ;
1147+ }
1148+
1149+ export function updateCustomAttribute ( attribute : RdfProperty ) {
1150+ const action = { type : ActionType . UPDATE_CUSTOM_ATTRIBUTE } ;
1151+ return ( dispatch : ThunkDispatch ) => {
1152+ dispatch ( asyncActionRequest ( action , true ) ) ;
1153+ return Ajax . put (
1154+ Constants . API_PREFIX +
1155+ "/data/custom-attributes/" +
1156+ VocabularyUtils . create ( attribute . iri ) . fragment ,
1157+ content ( attribute . toJsonLd ( ) )
1158+ )
1159+ . then ( ( ) => {
1160+ dispatch ( asyncActionSuccess ( action ) ) ;
1161+ dispatch (
1162+ publishMessage (
1163+ new Message (
1164+ {
1165+ messageId :
1166+ "administration.customization.customAttributes.update.success" ,
1167+ } ,
1168+ MessageType . SUCCESS
1169+ )
1170+ )
1171+ ) ;
1172+ } )
10961173 . catch ( ( error : ErrorData ) => dispatch ( asyncActionFailure ( action , error ) ) ) ;
10971174 } ;
10981175}
@@ -1249,6 +1326,28 @@ export function clearLongRunningTasksQueue() {
12491326 } ;
12501327}
12511328
1329+ export function reloadFullTextSearch ( ) {
1330+ const action = { type : ActionType . RELOAD_FTS } ;
1331+ return ( dispatch : ThunkDispatch ) => {
1332+ dispatch ( asyncActionRequest ( action ) ) ;
1333+ return Ajax . post ( `${ Constants . API_PREFIX } /admin/reload-fts` )
1334+ . then ( ( ) => dispatch ( asyncActionSuccess ( action ) ) )
1335+ . then ( ( ) =>
1336+ dispatch (
1337+ publishMessage (
1338+ new Message (
1339+ {
1340+ messageId : "administration.maintenance.reloadFTS.success" ,
1341+ } ,
1342+ MessageType . SUCCESS
1343+ )
1344+ )
1345+ )
1346+ )
1347+ . catch ( ( error ) => dispatch ( asyncActionFailure ( action , error ) ) ) ;
1348+ } ;
1349+ }
1350+
12521351export function loadConfiguration ( ) {
12531352 const action = { type : ActionType . LOAD_CONFIGURATION } ;
12541353 return ( dispatch : ThunkDispatch ) => {
@@ -1267,6 +1366,7 @@ export function loadConfiguration() {
12671366 data . roles = Utils . sanitizeArray ( data . roles ) . map (
12681367 ( d : UserRoleData ) => new UserRole ( d )
12691368 ) ;
1369+ data . indexedLanguages = Utils . sanitizeArray ( data . indexedLanguages ) ;
12701370 return dispatch ( asyncActionSuccessWithPayload ( action , data ) ) ;
12711371 } )
12721372 . catch ( ( error ) => dispatch ( asyncActionFailure ( action , error ) ) ) ;
0 commit comments