Changes field to metadatum and fields to metadata
This commit is contained in:
parent
90ed143980
commit
8ba7478287
|
@ -27,3 +27,4 @@ report.txt
|
|||
.tmp
|
||||
src/assets/css/tainacan-embeds.css
|
||||
src/assets/css/tainacan-embeds.css.map
|
||||
demosaved.csv
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
# Fields
|
||||
# Metadata
|
||||
|
||||
## Field Repository
|
||||
## Metadatum Repository
|
||||
|
||||
<!-- BEGIN DOC-COMMENT H3 src/classes/repositories/class-tainacan-fields.php -->
|
||||
### `class Fields extends Repository`
|
||||
<!-- BEGIN DOC-COMMENT H3 src/classes/repositories/class-tainacan-metadata.php -->
|
||||
### `class Metadata extends Repository`
|
||||
|
||||
Class Fields
|
||||
Class Metadata
|
||||
|
||||
|
||||
### `protected function __construct()`
|
||||
|
||||
Register specific hooks for field repository
|
||||
Register specific hooks for metadatum repository
|
||||
|
||||
|
||||
### `public function get_cpt_labels()`
|
||||
|
@ -20,14 +20,14 @@ Get the labels for the custom post type of this repository
|
|||
|
||||
### `public function get_default_metadata_attribute()`
|
||||
|
||||
constant used in default field in attribute collection_id
|
||||
constant used in default metadatum in attribute collection_id
|
||||
|
||||
|
||||
**Returns:** `string` — the value of constant
|
||||
|
||||
### `public function register_field_type( $class_name )`
|
||||
|
||||
register field types class on array of types
|
||||
register metadatum types class on array of types
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -36,7 +36,7 @@ register field types class on array of types
|
|||
|
||||
### `public function unregister_field_type( $class_name )`
|
||||
|
||||
register field types class on array of types
|
||||
register metadatum types class on array of types
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -45,21 +45,21 @@ register field types class on array of types
|
|||
|
||||
### `public function fetch( $args, $output = null )`
|
||||
|
||||
fetch field based on ID or WP_Query args
|
||||
fetch metadatum based on ID or WP_Query args
|
||||
|
||||
field are stored as posts. Check WP_Query docs to learn all args accepted in the $args parameter (@see https://developer.wordpress.org/reference/classes/wp_query/) You can also use a mapped property, such as name and description, as an argument and it will be mapped to the appropriate WP_Query argument
|
||||
metadatum are stored as posts. Check WP_Query docs to learn all args accepted in the $args parameter (@see https://developer.wordpress.org/reference/classes/wp_query/) You can also use a mapped property, such as name and description, as an argument and it will be mapped to the appropriate WP_Query argument
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
||||
* `$args` — array — WP_Query args || int $args the field id
|
||||
* `$args` — array — WP_Query args || int $args the metadatum id
|
||||
* `$output` — string — The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
|
||||
|
||||
**Returns:** `Entities\Field|\WP_Query|Array` — an instance of wp query OR array of entities;
|
||||
**Returns:** `Entities\Metadatum|\WP_Query|Array` — an instance of wp query OR array of entities;
|
||||
|
||||
### `public function fetch_by_collection(Entities\Collection $collection, $args = [], $output = null)`
|
||||
|
||||
fetch field by collection, searches all field available
|
||||
fetch metadatum by collection, searches all metadatum available
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -68,11 +68,11 @@ fetch field by collection, searches all field available
|
|||
* `$args` — array — WP_Query args plus disabled_fields
|
||||
* `$output` — string — The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
|
||||
|
||||
**Returns:** `array` — Entities\Field
|
||||
**Returns:** `array` — Entities\Metadatum
|
||||
|
||||
### `public function order_result( $result, Entities\Collection $collection, $include_disabled = false )`
|
||||
|
||||
Ordinate the result from fetch response if $collection has an ordination, fields not ordinated appear on the end of the list
|
||||
Ordinate the result from fetch response if $collection has an ordination, metadata not ordinated appear on the end of the list
|
||||
|
||||
|
||||
|
||||
|
@ -81,18 +81,18 @@ Ordinate the result from fetch response if $collection has an ordination, fields
|
|||
|
||||
* `Response` — $result — from method fetch
|
||||
* `$collection` — Entities\Collection
|
||||
* `$include_disabled` — bool — Wether to include disabled fields in the results or not
|
||||
* `$include_disabled` — bool — Wether to include disabled metadata in the results or not
|
||||
|
||||
**Returns:** `array` — or WP_Query ordinate
|
||||
|
||||
### `public function insert($field)`
|
||||
### `public function insert($metadatum)`
|
||||
|
||||
{@inheritDoc}
|
||||
**Parameters:**
|
||||
|
||||
* `$field` — \Tainacan\Entities\Field
|
||||
* `$metadatum` — \Tainacan\Entities\Metadatum
|
||||
|
||||
**Returns:** \Tainacan\Entities\Field
|
||||
**Returns:** \Tainacan\Entities\Metadatum
|
||||
|
||||
### `public function update($object, $new_values = null)`
|
||||
|
||||
|
@ -101,16 +101,16 @@ Ordinate the result from fetch response if $collection has an ordination, fields
|
|||
|
||||
### `public function fetch_field_types( $output = 'CLASS')`
|
||||
|
||||
fetch all registered field type classes
|
||||
fetch all registered metadatum type classes
|
||||
|
||||
Possible outputs are: CLASS (default) - returns the Class name of of field types registered NAME - return an Array of the names of field types registered
|
||||
Possible outputs are: CLASS (default) - returns the Class name of of metadatum types registered NAME - return an Array of the names of metadatum types registered
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
||||
* `string` — $output — CLASS | NAME
|
||||
|
||||
**Returns:** `array` — of Entities\Field_Types\Field_Type classes path name
|
||||
**Returns:** `array` — of Entities\Metadatum_Types\Metadatum_Type classes path name
|
||||
|
||||
### `public function register_core_fields( Entities\Collection $collection )`
|
||||
|
||||
|
@ -123,7 +123,7 @@ Possible outputs are: CLASS (default) - returns the Class name of of field types
|
|||
|
||||
### `public function disable_delete_core_fields( $before, $post )`
|
||||
|
||||
block user from remove core fields
|
||||
block user from remove core metadata
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -135,7 +135,7 @@ block user from remove core fields
|
|||
|
||||
### `public function force_delete_core_fields( $before, $post, $force_delete )`
|
||||
|
||||
block user from remove core fields ( if use wp_delete_post)
|
||||
block user from remove core metadata ( if use wp_delete_post)
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -159,72 +159,72 @@ returns all core items from a specific collection
|
|||
|
||||
### `public function insert_array_field( $data )`
|
||||
|
||||
create a field entity and insert by an associative array ( attribute => value )
|
||||
create a metadatum entity and insert by an associative array ( attribute => value )
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
||||
* `$data` — Array — the array of attributes to insert a field
|
||||
* `$data` — Array — the array of attributes to insert a metadatum
|
||||
|
||||
**Returns:** `int` — the field id inserted
|
||||
**Returns:** `int` — the metadatum id inserted
|
||||
|
||||
### `public function fetch_all_field_values($collection_id, $field_id)`
|
||||
### `public function fetch_all_field_values($collection_id, $metadatum_id)`
|
||||
|
||||
Fetch all values of a field from a collection in all it collection items
|
||||
Fetch all values of a metadatum from a collection in all it collection items
|
||||
|
||||
|
||||
**Returns:** array|null|object
|
||||
|
||||
### `private function pre_update_category_field($field)`
|
||||
### `private function pre_update_category_field($metadatum)`
|
||||
|
||||
Stores the value of the taxonomy_id option to use on update_category_field method.
|
||||
|
||||
|
||||
|
||||
|
||||
### `private function update_category_field($field)`
|
||||
### `private function update_category_field($metadatum)`
|
||||
|
||||
Triggers hooks when saving a Category Field, indicating wich taxonomy was added or removed from a collection.
|
||||
Triggers hooks when saving a Category Metadatum, indicating wich taxonomy was added or removed from a collection.
|
||||
|
||||
This is used by Taxonomies repository to update the collections_ids property of the taxonomy as a field type category is inserted or removed
|
||||
This is used by Taxonomies repository to update the collections_ids property of the taxonomy as a metadatum type category is inserted or removed
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
||||
* `$field` — [type] — [description]
|
||||
* `$metadatum` — [type] — [description]
|
||||
|
||||
**Returns:** `[type]` — [description]
|
||||
|
||||
<!-- END DOC-COMMENT -->
|
||||
|
||||
## Field Entity
|
||||
## Metadatum Entity
|
||||
|
||||
<!-- BEGIN DOC-COMMENT H3 src/classes/entities/class-tainacan-field.php -->
|
||||
### `class Field extends Entity`
|
||||
<!-- BEGIN DOC-COMMENT H3 src/classes/entities/class-tainacan-metadatum.php -->
|
||||
### `class Metadatum extends Entity`
|
||||
|
||||
Represents the Entity Field
|
||||
Represents the Entity Metadatum
|
||||
|
||||
|
||||
### `protected $repository = 'Fields'`
|
||||
### `protected $repository = 'Metadata'`
|
||||
|
||||
{@inheritDoc}
|
||||
### `function get_name()`
|
||||
|
||||
Return the field name
|
||||
Return the metadatum name
|
||||
|
||||
|
||||
**Returns:** string
|
||||
|
||||
### `function get_slug()`
|
||||
|
||||
Get field slug
|
||||
Get metadatum slug
|
||||
|
||||
|
||||
**Returns:** string
|
||||
|
||||
### `function get_order()`
|
||||
|
||||
Return the field order type
|
||||
Return the metadatum order type
|
||||
|
||||
|
||||
**Returns:** string
|
||||
|
@ -238,21 +238,21 @@ Return the parent ID
|
|||
|
||||
### `function get_description()`
|
||||
|
||||
Return the field description
|
||||
Return the metadatum description
|
||||
|
||||
|
||||
**Returns:** string
|
||||
|
||||
### `function get_required()`
|
||||
|
||||
Return if is a required field
|
||||
Return if is a required metadatum
|
||||
|
||||
|
||||
**Returns:** boolean
|
||||
|
||||
### `function get_multiple()`
|
||||
|
||||
Return if is a multiple field
|
||||
Return if is a multiple metadatum
|
||||
|
||||
|
||||
**Returns:** boolean
|
||||
|
@ -266,7 +266,7 @@ Return the cardinality
|
|||
|
||||
### `function get_collection_key()`
|
||||
|
||||
Return if field is key
|
||||
Return if metadatum is key
|
||||
|
||||
|
||||
**Returns:** boolean
|
||||
|
@ -280,35 +280,35 @@ Return the mask
|
|||
|
||||
### `function get_default_value()`
|
||||
|
||||
Return the field default value
|
||||
Return the metadatum default value
|
||||
|
||||
|
||||
**Returns:** `string` — || integer
|
||||
|
||||
### `function get_field_type_object()`
|
||||
|
||||
Return the an object child of \Tainacan\Field_Types\Field_Type with options
|
||||
Return the an object child of \Tainacan\Metadatum_Types\Metadatum_Type with options
|
||||
|
||||
|
||||
**Returns:** `\Tainacan\Field_Types\Field_Type` — The field type class with filled options
|
||||
**Returns:** `\Tainacan\Metadatum_Types\Metadatum_Type` — The metadatum type class with filled options
|
||||
|
||||
### `function get_field_type()`
|
||||
|
||||
Return the class name for the field type
|
||||
Return the class name for the metadatum type
|
||||
|
||||
|
||||
**Returns:** `string` — The
|
||||
|
||||
### `function get_field_type_options()`
|
||||
|
||||
Return the actual options for the current field type
|
||||
Return the actual options for the current metadatum type
|
||||
|
||||
|
||||
**Returns:** `array` — Configurations for the field type object
|
||||
**Returns:** `array` — Configurations for the metadatum type object
|
||||
|
||||
### `function set_name($value)`
|
||||
|
||||
Set the field name
|
||||
Set the metadatum name
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -319,14 +319,14 @@ Set the field name
|
|||
|
||||
### `function get_accept_suggestion()`
|
||||
|
||||
Return true if this field allow community suggestions, false otherwise
|
||||
Return true if this metadatum allow community suggestions, false otherwise
|
||||
**Returns:** bool
|
||||
|
||||
### `function set_slug($value)`
|
||||
|
||||
Set the field slug
|
||||
Set the metadatum slug
|
||||
|
||||
If you dont set the field slug, it will be set automatically based on the name and following WordPress default behavior of creating slugs for posts.
|
||||
If you dont set the metadatum slug, it will be set automatically based on the name and following WordPress default behavior of creating slugs for posts.
|
||||
|
||||
If you set the slug for an existing one, WordPress will append a number at the end of in order to make it unique (e.g slug-1, slug-2)
|
||||
|
||||
|
@ -339,7 +339,7 @@ If you set the slug for an existing one, WordPress will append a number at the e
|
|||
|
||||
### `function set_order($value)`
|
||||
|
||||
Set manually the order of the field
|
||||
Set manually the order of the metadatum
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -350,7 +350,7 @@ Set manually the order of the field
|
|||
|
||||
### `function set_parent($value)`
|
||||
|
||||
Set the field parent ID
|
||||
Set the metadatum parent ID
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -361,7 +361,7 @@ Set the field parent ID
|
|||
|
||||
### `function set_description($value)`
|
||||
|
||||
Set field description
|
||||
Set metadatum description
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -372,7 +372,7 @@ Set field description
|
|||
|
||||
### `function set_required( $value )`
|
||||
|
||||
Allow the field be required
|
||||
Allow the metadatum be required
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -383,7 +383,7 @@ Allow the field be required
|
|||
|
||||
### `function set_multiple( $value )`
|
||||
|
||||
Allow multiple fields
|
||||
Allow multiple metadata
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -394,7 +394,7 @@ Allow multiple fields
|
|||
|
||||
### `function set_cardinality( $value )`
|
||||
|
||||
The number of possible fields
|
||||
The number of possible metadata
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -416,7 +416,7 @@ Define if the value is key on the collection
|
|||
|
||||
### `function set_mask( $value )`
|
||||
|
||||
Set mask for the field
|
||||
Set mask for the metadatum
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -449,23 +449,23 @@ Set default value
|
|||
|
||||
### `public function set_field_type( $value )`
|
||||
|
||||
set the field type class name
|
||||
set the metadatum type class name
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
||||
* `|` — string — \Tainacan\Field_Types\Field_Type $value The name of the class or the instance
|
||||
* `|` — string — \Tainacan\Metadatum_Types\Metadatum_Type $value The name of the class or the instance
|
||||
|
||||
### `function set_accept_suggestion( $value )`
|
||||
|
||||
Set if this field allow community suggestions
|
||||
Set if this metadatum allow community suggestions
|
||||
**Parameters:**
|
||||
|
||||
* `$value` — bool
|
||||
|
||||
### `function set_field_type_options( $value )`
|
||||
|
||||
Set Field type options
|
||||
Set Metadatum type options
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -476,9 +476,9 @@ Set Field type options
|
|||
|
||||
### `public function get_enabled_for_collection()`
|
||||
|
||||
Transient property used to store the status of the field for a particular collection
|
||||
Transient property used to store the status of the metadatum for a particular collection
|
||||
|
||||
Used by the API to tell front end when a field is disabled
|
||||
Used by the API to tell front end when a metadatum is disabled
|
||||
|
||||
|
||||
|
||||
|
@ -508,7 +508,7 @@ Return true if is required, else return false
|
|||
|
||||
{@inheritdoc }
|
||||
|
||||
Also validates the field, calling the validate_options callback of the Field Type
|
||||
Also validates the metadatum, calling the validate_options callback of the Metadatum Type
|
||||
|
||||
|
||||
**Returns:** `bool` — valid or not
|
||||
|
|
|
@ -28,7 +28,7 @@ Filters are stored as posts. Check WP_Query docs to learn all args accepted in t
|
|||
|
||||
### `public function register_filter_type( $class_name )`
|
||||
|
||||
register field types class on array of types
|
||||
register metadatum types class on array of types
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -37,7 +37,7 @@ register field types class on array of types
|
|||
|
||||
### `public function deregister_filter_type( $class_name )`
|
||||
|
||||
register field types class on array of types
|
||||
register metadatum types class on array of types
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -64,7 +64,7 @@ fetch only supported filters for the type specified
|
|||
|
||||
**Parameters:**
|
||||
|
||||
* `string` — ( — || array ) $types Primitve types of field ( float, string, int)
|
||||
* `string` — ( — || array ) $types Primitve types of metadatum ( float, string, int)
|
||||
|
||||
**Returns:** `array` — Filters supported by the primitive types passed in $types
|
||||
|
||||
|
@ -79,7 +79,7 @@ fetch filters by collection, searches all filters available
|
|||
* `$args` — array — WP_Query args plus disabled_fields
|
||||
* `$output` — string — The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
|
||||
|
||||
**Returns:** `Array` — Entities\Field
|
||||
**Returns:** `Array` — Entities\Metadatum
|
||||
|
||||
### `public function order_result( $result, Entities\Collection $collection )`
|
||||
|
||||
|
@ -141,10 +141,10 @@ Return the filter color
|
|||
|
||||
### `function get_field()`
|
||||
|
||||
Return the field
|
||||
Return the metadatum
|
||||
|
||||
|
||||
**Returns:** Field
|
||||
**Returns:** Metadatum
|
||||
|
||||
### `function get_filter_type_object()`
|
||||
|
||||
|
@ -213,7 +213,7 @@ Define the filter color
|
|||
|
||||
### `function set_field( $value )`
|
||||
|
||||
Define the filter field
|
||||
Define the filter metadatum
|
||||
|
||||
|
||||
**Returns:** void
|
||||
|
@ -231,7 +231,7 @@ Save the filter type class name
|
|||
|
||||
{@inheritdoc }
|
||||
|
||||
Also validates the field, calling the validate_options callback of the Field Type
|
||||
Also validates the metadatum, calling the validate_options callback of the Metadatum Type
|
||||
|
||||
|
||||
**Returns:** `bool` — valid or not
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
<!-- BEGIN DOC-COMMENT H3 src/classes/repositories/class-tainacan-item-metadata.php -->
|
||||
### `if ( $item_metadata->get_field()->get_parent() > 0 && is_null($item_metadata->get_meta_id()) )`
|
||||
|
||||
When we are adding a field that is child of another, this means it is inside a compound field
|
||||
When we are adding a metadatum that is child of another, this means it is inside a compound metadatum
|
||||
|
||||
In that case, if the Item_Metadata object is not set with a meta_id, it means we want to create a new one and not update an existing. This is the case of a multiple compound field.
|
||||
In that case, if the Item_Metadata object is not set with a meta_id, it means we want to create a new one and not update an existing. This is the case of a multiple compound metadatum.
|
||||
|
||||
|
||||
### `public function delete($item_metadata)`
|
||||
|
@ -24,7 +24,7 @@ In that case, if the Item_Metadata object is not set with a meta_id, it means we
|
|||
|
||||
### `public function fetch($object, $output = null )`
|
||||
|
||||
Fetch Item Field objects related to an Item
|
||||
Fetch Item Metadatum objects related to an Item
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -35,7 +35,7 @@ Fetch Item Field objects related to an Item
|
|||
|
||||
### `public function get_value(Entities\Item_Metadata_Entity $item_metadata)`
|
||||
|
||||
Get the value for a Item field.
|
||||
Get the value for a Item metadatum.
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -46,7 +46,7 @@ Get the value for a Item field.
|
|||
|
||||
### `private function extract_compound_value(array $ids, Entities\Item $item, $compund_meta_id)`
|
||||
|
||||
Transforms the array saved as meta_value with the IDs of post_meta saved as a value for compound fields and converts it into an array of Item Metadatada Entitites
|
||||
Transforms the array saved as meta_value with the IDs of post_meta saved as a value for compound metadata and converts it into an array of Item Metadatada Entitites
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -64,7 +64,7 @@ Transforms the array saved as meta_value with the IDs of post_meta saved as a va
|
|||
|
||||
### `public function suggest($item_metadata)`
|
||||
|
||||
Suggest a value to be inserted as a item Field value, return a pending log
|
||||
Suggest a value to be inserted as a item Metadatum value, return a pending log
|
||||
**Parameters:**
|
||||
|
||||
* `$item_metadata` — Entities\Item_Metadata_Entity
|
||||
|
@ -78,13 +78,13 @@ Suggest a value to be inserted as a item Field value, return a pending log
|
|||
<!-- BEGIN DOC-COMMENT H3 src/classes/entities/class-tainacan-item-metadata-entity.php -->
|
||||
### `class Item_Metadata_Entity extends Entity`
|
||||
|
||||
Represents the Item Field Entity
|
||||
Represents the Item Metadatum Entity
|
||||
|
||||
|
||||
### `protected $repository = 'Item_Metadata'`
|
||||
|
||||
{@inheritDoc}
|
||||
### `function __construct(Item $item, Field $field, $meta_id = null, $parent_meta_id = null)`
|
||||
### `function __construct(Item $item, Metadatum $metadatum, $meta_id = null, $parent_meta_id = null)`
|
||||
|
||||
|
||||
|
||||
|
@ -92,7 +92,7 @@ Represents the Item Field Entity
|
|||
**Parameters:**
|
||||
|
||||
* `$item` — Item — Item Entity
|
||||
* `$field` — Field — Field Entity
|
||||
* `$metadatum` — Metadatum — Metadatum Entity
|
||||
* `$meta_id` — int — ID for a specific meta row
|
||||
|
||||
### `function set_item(Item $item)`
|
||||
|
@ -108,7 +108,7 @@ Define the item
|
|||
|
||||
### `function set_value($value)`
|
||||
|
||||
Define the field value
|
||||
Define the metadatum value
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -117,14 +117,14 @@ Define the field value
|
|||
|
||||
**Returns:** void
|
||||
|
||||
### `function set_field(Field $field)`
|
||||
### `function set_field(Metadatum $metadatum)`
|
||||
|
||||
Define the field
|
||||
Define the metadatum
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
||||
* `$field` — Field
|
||||
* `$metadatum` — Metadatum
|
||||
|
||||
**Returns:** void
|
||||
|
||||
|
@ -132,7 +132,7 @@ Define the field
|
|||
|
||||
Set the specific meta ID for this metadata.
|
||||
|
||||
When this value is set, get_value() will use it to fetch the value from the post_meta table, instead of considering the item and field IDs
|
||||
When this value is set, get_value() will use it to fetch the value from the post_meta table, instead of considering the item and metadatum IDs
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -141,9 +141,9 @@ When this value is set, get_value() will use it to fetch the value from the post
|
|||
|
||||
### `function set_parent_meta_id($parent_meta_id)`
|
||||
|
||||
Set parent_meta_id. Used when a item_metadata is inside a compound Field
|
||||
Set parent_meta_id. Used when a item_metadata is inside a compound Metadatum
|
||||
|
||||
When you have a multiple compound field, this indicates of which instace of the value this item_metadata is attached to
|
||||
When you have a multiple compound metadatum, this indicates of which instace of the value this item_metadata is attached to
|
||||
|
||||
|
||||
**Parameters:**
|
||||
|
@ -159,49 +159,49 @@ Return the item
|
|||
|
||||
### `function get_field()`
|
||||
|
||||
Return the field
|
||||
Return the metadatum
|
||||
|
||||
|
||||
**Returns:** Field
|
||||
**Returns:** Metadatum
|
||||
|
||||
### `function get_meta_id()`
|
||||
|
||||
Return the meta_id
|
||||
|
||||
|
||||
**Returns:** Field
|
||||
**Returns:** Metadatum
|
||||
|
||||
### `function get_parent_meta_id()`
|
||||
|
||||
Return the meta_id
|
||||
|
||||
|
||||
**Returns:** Field
|
||||
**Returns:** Metadatum
|
||||
|
||||
### `function get_value()`
|
||||
|
||||
Return the field value
|
||||
Return the metadatum value
|
||||
|
||||
|
||||
**Returns:** `string` — | integer
|
||||
|
||||
### `function is_multiple()`
|
||||
|
||||
Return true if field is multiple, else return false
|
||||
Return true if metadatum is multiple, else return false
|
||||
|
||||
|
||||
**Returns:** boolean
|
||||
|
||||
### `function is_collection_key()`
|
||||
|
||||
Return true if field is key
|
||||
Return true if metadatum is key
|
||||
|
||||
|
||||
**Returns:** boolean
|
||||
|
||||
### `function is_required()`
|
||||
|
||||
Return true if field is required
|
||||
Return true if metadatum is required
|
||||
|
||||
|
||||
**Returns:** boolean
|
||||
|
|
|
@ -240,9 +240,9 @@ Define the description
|
|||
|
||||
Return a List of ItemMetadata objects
|
||||
|
||||
It will return all fields associeated with the collection this item is part of.
|
||||
It will return all metadata associeated with the collection this item is part of.
|
||||
|
||||
If the item already has a value for any of the fields, it will be available.
|
||||
If the item already has a value for any of the metadata, it will be available.
|
||||
|
||||
|
||||
**Returns:** `array` — Array of ItemMetadata objects
|
||||
|
|
|
@ -6,9 +6,9 @@ But sometimes you dont want just to have your collections browsable via web, you
|
|||
|
||||
## Mapping
|
||||
|
||||
With Tainacan you have the possibility to map your collection structure to one or more known standards you may want to be compatible with. So even if you use a custom set of fields to describe your collection, you may be compatible and interoperate with other repositories.
|
||||
With Tainacan you have the possibility to map your collection structure to one or more known standards you may want to be compatible with. So even if you use a custom set of metadata to describe your collection, you may be compatible and interoperate with other repositories.
|
||||
|
||||
You do it by informing, for each field you create, what is it relative in each format you want to map your collection to. You may say for example, that you "Name" Field is the equivalent to the dc:Title attribute in Dublin Core and some another attribute in other format you choose.
|
||||
You do it by informing, for each metadatum you create, what is it relative in each format you want to map your collection to. You may say for example, that you "Name" Metadatum is the equivalent to the dc:Title attribute in Dublin Core and some another attribute in other format you choose.
|
||||
|
||||
Tainacan is shipped with some Mapping standards that implement popular metadata standards. And it will be easy to create new standards. See more [details about mapping standards](mapping-standards.md).
|
||||
|
||||
|
@ -18,13 +18,13 @@ You can also use these mapping standards as a pre-set when you create a new Coll
|
|||
|
||||
Exporting allows you to download the content of your repository to a file - or to multiple files. The format of the package you will download depends on the exporter you will use. Tainacan ships with a simple CSV exporter and a Tainacan-Package exporter, that allows you to export all the content of your collections, including the attachments, to import in another Tainacan instance.
|
||||
|
||||
Whatever exporter you choose to you use, you will be able to choose wether you want to download the collection as it is, which means, with the fields the way the were created in Tainacan, or wether you want to download it in a mapped version. For example, if you mapped your collection to Dublin Core, you can download a CSV file either in Dublin Core format or in the original format.
|
||||
Whatever exporter you choose to you use, you will be able to choose wether you want to download the collection as it is, which means, with the metadata the way the were created in Tainacan, or wether you want to download it in a mapped version. For example, if you mapped your collection to Dublin Core, you can download a CSV file either in Dublin Core format or in the original format.
|
||||
|
||||
Tainacan makes it very easy to developers to create new exporters and publish them as plugins anyone can use.
|
||||
|
||||
## Exposing
|
||||
|
||||
Tainacan is powered with an API that allows other applications to search and consume the content of your repository. By default, this API serves the content in JSON format, preserving the fields in the collections the way you created them.
|
||||
Tainacan is powered with an API that allows other applications to search and consume the content of your repository. By default, this API serves the content in JSON format, preserving the metadata in the collections the way you created them.
|
||||
|
||||
In the same way you can choose the format of the file when you export your collection, one can choose the format he/she want to consume yout content in. This is what exposers are for.
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
* everything auto draft
|
||||
* post_meta of deleted fields
|
||||
* post_meta of deleted instaces of a multiple compound Field. post_meta of a field that is child of a compound field, but which the ID does not appear in any array of a compound field meta_value
|
||||
* post_meta of deleted metadata
|
||||
* post_meta of deleted instaces of a multiple compound Metadatum. post_meta of a metadatum that is child of a compound metadatum, but which the ID does not appear in any array of a compound metadatum meta_value
|
||||
* orphan terms (with taxonomy that does not exist)
|
|
@ -18,7 +18,7 @@ If called from inside a collection, this step is skipped and the current collect
|
|||
If the importer has the attribute `$import_structure_and_mapping` set to `true`, and the importer is called from repository level,
|
||||
they will also be able to choose to create a new collection.
|
||||
|
||||
In that cases, a new collection is created, and the importer must implement a method called `create_fields_and_mapping()`, which, as the name says, will create all collections fields and set the mapping for the importer.
|
||||
In that cases, a new collection is created, and the importer must implement a method called `create_fields_and_mapping()`, which, as the name says, will create all collections metadata and set the mapping for the importer.
|
||||
|
||||
|
||||
## Set options
|
||||
|
@ -79,12 +79,12 @@ From that point forward, the importer will behave just as if it was using the fi
|
|||
|
||||
## Mapping
|
||||
|
||||
At this point the user is presented with an interface to map the fields from the source to the fields present in the chosen collection.
|
||||
At this point the user is presented with an interface to map the metadata from the source to the metadata present in the chosen collection.
|
||||
|
||||
The Importer class must implement the `get_fields()` method, that will return an array of the fields found in the source. It can either return an hard coded array or an array that is red from the source file. For example, an importer that fetches data from an api knows beforehand what are the fields the api will return, however, an importer that reads from a csv, may want to return whatever is found in the first line of the array.
|
||||
The Importer class must implement the `get_fields()` method, that will return an array of the metadata found in the source. It can either return an hard coded array or an array that is red from the source file. For example, an importer that fetches data from an api knows beforehand what are the metadata the api will return, however, an importer that reads from a csv, may want to return whatever is found in the first line of the array.
|
||||
|
||||
```
|
||||
// Example 1: returns a hard coded set of fields
|
||||
// Example 1: returns a hard coded set of metadata
|
||||
function get_fields() {
|
||||
return [
|
||||
'title',
|
||||
|
@ -103,7 +103,7 @@ public function get_fields(){
|
|||
|
||||
## Importing Collection Structure and Mapping
|
||||
|
||||
Alternatively, an importer may also create all the fields and mappings from the source. In that cases, the user does not have to map anything.
|
||||
Alternatively, an importer may also create all the metadata and mappings from the source. In that cases, the user does not have to map anything.
|
||||
|
||||
First thing an Importer must do to accomplish this is to declare it does so in the `construct()`, by setting `$import_structure_and_mapping` to `true`.
|
||||
|
||||
|
@ -115,38 +115,38 @@ function __construct() {
|
|||
}
|
||||
```
|
||||
|
||||
Second, the importer must implement the `create_fields_and_mapping()` to populate the collection with fields and set the mapping.
|
||||
Second, the importer must implement the `create_fields_and_mapping()` to populate the collection with metadata and set the mapping.
|
||||
|
||||
In order to do this, the Importer will use Tainacan internal API to create the fields. Please refer to the documentation (TODO: write this documentation).
|
||||
In order to do this, the Importer will use Tainacan internal API to create the metadata. Please refer to the documentation (TODO: write this documentation).
|
||||
|
||||
This method must be aware that even a brand new collection comes with two core fields (title and description), and use them.
|
||||
This method must be aware that even a brand new collection comes with two core metadata (title and description), and use them.
|
||||
|
||||
Again, this fields can come from the file, the URL or may be hardcoded in the function.
|
||||
Again, this metadata can come from the file, the URL or may be hardcoded in the function.
|
||||
|
||||
Example
|
||||
```
|
||||
function create_fields_and_mapping() {
|
||||
|
||||
$fields_repository = \Tainacan\Repositories\Fields::get_instance();
|
||||
$metadata_repository = \Tainacan\Repositories\Metadata::get_instance();
|
||||
|
||||
$newField1 = new \Tainacan\Entities\Field();
|
||||
$newField1->set_name = 'New Field';
|
||||
$newField1->set_field_type = 'Tainacan\Field_Types\Text';
|
||||
$newField1->set_collection($this->collection);
|
||||
$newMetadatum1 = new \Tainacan\Entities\Metadatum();
|
||||
$newMetadatum1->set_name = 'New Metadatum';
|
||||
$newMetadatum1->set_field_type = 'Tainacan\Metadatum_Types\Text';
|
||||
$newMetadatum1->set_collection($this->collection);
|
||||
|
||||
$newField1->validate(); // there is no user input here, so we can be sure it will validate.
|
||||
$newMetadatum1->validate(); // there is no user input here, so we can be sure it will validate.
|
||||
|
||||
$newField1 = $fields_repository->insert($newField1);
|
||||
$newMetadatum1 = $metadata_repository->insert($newMetadatum1);
|
||||
|
||||
$source_fields = $this->get_fields();
|
||||
|
||||
$this->set_mapping([
|
||||
$newField1->get_id() => $source_fields[0]
|
||||
$newMetadatum1->get_id() => $source_fields[0]
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
TODO: helpers and explanation on how to fetch the core fields and map them
|
||||
TODO: helpers and explanation on how to fetch the core metadata and map them
|
||||
|
||||
```
|
||||
|
||||
|
@ -159,6 +159,6 @@ The `run()` method is called, the importer runs a step of the import process, an
|
|||
|
||||
In order to allow this, the importer must implement the `get_total_items_from_source()` method, which will inform the total number of items present in the source.
|
||||
|
||||
All the steps and insertion are handled by the Importer super class. The importer class only have to implement one method (`process_item()`) to handle one single item. It will receive the index of this item and it must return the item in as an array, where each key is the identifier of the source field (the same used in the mapping array), and the values are each field value.
|
||||
All the steps and insertion are handled by the Importer super class. The importer class only have to implement one method (`process_item()`) to handle one single item. It will receive the index of this item and it must return the item in as an array, where each key is the identifier of the source metadatum (the same used in the mapping array), and the values are each metadatum value.
|
||||
|
||||
In the end, a report is generated with all the logs generated in the process.
|
|
@ -1,6 +1,6 @@
|
|||
# Tainacan Internal API
|
||||
|
||||
This page shows how the internal API works and how to create and fetch all kinds of entities in Tainacan: Collections, items, taxnomies, fields, filters, terms, item metadata and logs.
|
||||
This page shows how the internal API works and how to create and fetch all kinds of entities in Tainacan: Collections, items, taxnomies, metadata, filters, terms, item metadata and logs.
|
||||
|
||||
Its important that you first get familiar with the [key concepts](key-concepts.md) of tainacan.
|
||||
|
||||
|
@ -9,7 +9,7 @@ This page gives an overview of the API. Detailed documentation and reference on
|
|||
* [Collections Reference](class-reference-collections.md)
|
||||
* [Items Reference](class-reference-items.md)
|
||||
* [Item Metadata Reference](class-reference-item-metadata.md)
|
||||
* [Fields Reference](class-reference-fields.md)
|
||||
* [Metadata Reference](class-reference-metadata.md)
|
||||
* [Filters Reference](class-reference-filters.md)
|
||||
* [Taxonomies Reference](class-reference-taxonomies.md)
|
||||
* [Terms Reference](class-reference-terms.md)
|
||||
|
@ -24,21 +24,21 @@ This layer is based on a Repository pattern. Each entity Tainacan deals with hav
|
|||
Repositories are the classes that comunicate with the database and know where everything is stored and how to find things. It is a singleton class, so it have only one instance available to be used by any part of the application.
|
||||
|
||||
```PHP
|
||||
$fields_repo = Tainacan\Repositories\Fields::get_instance();
|
||||
$metadata_repo = Tainacan\Repositories\Metadata::get_instance();
|
||||
```
|
||||
Entities classes are the representation of the individual of each repository.
|
||||
|
||||
This abstraction allows us to easily manipulate entities without worrying how to save or fetch them.
|
||||
|
||||
For example, Fields have many attributes, such as `name` and `required` (indicating wether this field is required or not). As mentioned before, Fields are stored as posts of a special post type called `tainacan-field`. The name of the field is, of course, the `post_title` and this `required` attribute is stored as a `post_meta`.
|
||||
For example, Metadata have many attributes, such as `name` and `required` (indicating wether this metadatum is required or not). As mentioned before, Metadata are stored as posts of a special post type called `tainacan-metadatum`. The name of the metadatum is, of course, the `post_title` and this `required` attribute is stored as a `post_meta`.
|
||||
|
||||
However, you dont need to bother about that. This pattern allows you to manipulate a Field entity and it attributes in a transparent way, such as:
|
||||
|
||||
```PHP
|
||||
$field->get_name(); // returns the field name
|
||||
$field->get_required(); // returns the required value
|
||||
$field->set_name('new name');
|
||||
$field->set_required('yes');
|
||||
$metadatum->get_name(); // returns the metadatum name
|
||||
$metadatum->get_required(); // returns the required value
|
||||
$metadatum->set_name('new name');
|
||||
$metadatum->set_required('yes');
|
||||
```
|
||||
|
||||
Tainacan will automatically map the values of the attributes to and from where they are stored.
|
||||
|
@ -46,7 +46,7 @@ Tainacan will automatically map the values of the attributes to and from where t
|
|||
When you want to fetch entities from the database, this abstraction layer steps aside and let you use all the power and flexibility of `WP_Query`, which you know and love. For example:
|
||||
|
||||
```PHP
|
||||
Repositories\Fields::get_instance()->fetch('s=test');
|
||||
Repositories\Metadata::get_instance()->fetch('s=test');
|
||||
```
|
||||
|
||||
The `fetch` method from the repositories accept exactly the same arguments accepted by `WP_Query` and uses it internally. In fact, you could use `WP_Query` directly if you prefer, but using the repository class gives you some advantages. You dont have to know the name of the post type, you can also fetch by some mapped attribute calling it directly, withour having to use `meta_query` (or even know wether a property is stored as a post attribute or post_meta). See more details in the Fetch section below.
|
||||
|
@ -106,15 +106,15 @@ $items = $items_repo->fetch([
|
|||
Note that you can use the mapped attribute names to build your query, but it is just fine if you want to use the native WordPress names. The same can be achievied with attributes stored as post_meta:
|
||||
|
||||
```PHP
|
||||
$repo = Tainacan\Repositories\Fields::get_instance();
|
||||
$repo = Tainacan\Repositories\Metadata::get_instance();
|
||||
|
||||
$fields = $repo->fetch([
|
||||
$metadata = $repo->fetch([
|
||||
'required' => 'yes'
|
||||
]);
|
||||
|
||||
// is the same as
|
||||
|
||||
$fields = $repo->fetch([
|
||||
$metadata = $repo->fetch([
|
||||
'meta_query' => [
|
||||
[
|
||||
'key' => 'required',
|
||||
|
@ -176,13 +176,13 @@ Well, Item Metadata Entity is slightly different.
|
|||
|
||||
`Item Metada` is a special kind of entity, because it is not an actual entity itself. Rather, it is the relationship between an Item and a Field. And this relationship has a value.
|
||||
|
||||
So imagine a Collection of pens has a Field called "color". This means the an item of this collection will have a relationship with this field, and this relation will have a value. Red, for example.
|
||||
So imagine a Collection of pens has a Field called "color". This means the an item of this collection will have a relationship with this metadatum, and this relation will have a value. Red, for example.
|
||||
|
||||
So the Item Metadata Entity constructor gets to entities: an item and a field. Lets see an example, considering I alredy have a collection with fields and an item.
|
||||
So the Item Metadata Entity constructor gets to entities: an item and a metadatum. Lets see an example, considering I alredy have a collection with metadata and an item.
|
||||
|
||||
```PHP
|
||||
// Considering $item is an existing Item Entity an $field an existing Field Entity
|
||||
$itemMetadada = new \Tainacan\Entities\ItemMetadataEntity($item, $field);
|
||||
// Considering $item is an existing Item Entity an $metadatum an existing Field Entity
|
||||
$itemMetadada = new \Tainacan\Entities\ItemMetadataEntity($item, $metadatum);
|
||||
|
||||
$itemMetadata->set_value('Red');
|
||||
|
||||
|
@ -195,20 +195,20 @@ if ($itemMetadata->validate()) {
|
|||
|
||||
```
|
||||
|
||||
> Note: "Multiple" Fields, which can have more than one value for the same item, work exactly the same way, with the difference that its value is an array of values, and not just one single value.
|
||||
> Note: "Multiple" Metadata, which can have more than one value for the same item, work exactly the same way, with the difference that its value is an array of values, and not just one single value.
|
||||
|
||||
If you want to iterate over all fields of an item or a collection, there are 2 usefull methods you can use. Fields repository have a `fetch_by_collection()` method that will fetch all fields from a given collection and return them in the right order.
|
||||
If you want to iterate over all metadata of an item or a collection, there are 2 usefull methods you can use. Metadata repository have a `fetch_by_collection()` method that will fetch all metadata from a given collection and return them in the right order.
|
||||
|
||||
Also, ItemMetadata Repository `fetch()` method will return an array of ItemMetadata Entities related to a given item.
|
||||
|
||||
|
||||
### Handling Compound fields
|
||||
### Handling Compound metadata
|
||||
|
||||
Compound fields are a special type of fields that support child fields. It is a group of fields.
|
||||
Compound metadata are a special type of metadata that support child metadata. It is a group of metadata.
|
||||
|
||||
The Compound field itself does not have a value, only its children have. So when you are saving a new value for a child field of a compound field, it will behave as it was a normal field.
|
||||
The Compound metadatum itself does not have a value, only its children have. So when you are saving a new value for a child metadatum of a compound metadatum, it will behave as it was a normal metadatum.
|
||||
|
||||
However, when you save the value for the second field of that same group, you must inform that it belong to that group. You do this by passing a `parent_meta_id` when initializing the Item Metada Entity. Note that you will only have this ID after you saved the first ItemMetadata of that group, because only then the group was created.
|
||||
However, when you save the value for the second metadatum of that same group, you must inform that it belong to that group. You do this by passing a `parent_meta_id` when initializing the Item Metada Entity. Note that you will only have this ID after you saved the first ItemMetadata of that group, because only then the group was created.
|
||||
|
||||
```PHP
|
||||
|
||||
|
@ -239,10 +239,10 @@ $compoundValue = $compoundItemMeta->get_value();
|
|||
|
||||
// This is an array of ItemMetadata Entities
|
||||
|
||||
foreach ($compoundValue as $field_id => $childItemMeta) {
|
||||
foreach ($compoundValue as $metadatum_id => $childItemMeta) {
|
||||
var_dump( $childItemMeta instanceof \Tainacan\Entities\ItemMetadataEntity ); // true
|
||||
var_dump( $field_id == $childItemMeta->get_field()->get_id() ); // true
|
||||
echo "Value for field " . $childItemMeta->get_field()->get_name() " (child of " . $compoundItemMeta->get_name() . ") is:" . $childItemMeta->get_value();
|
||||
var_dump( $metadatum_id == $childItemMeta->get_field()->get_id() ); // true
|
||||
echo "Value for metadatum " . $childItemMeta->get_field()->get_name() " (child of " . $compoundItemMeta->get_name() . ") is:" . $childItemMeta->get_value();
|
||||
var_dump( $childItemMeta->get_field()->get_parent() == compoundItemMeta->get_field()->get_id() ); // true
|
||||
var_dump( is_int($childItemMeta->get_meta_id()) && $childItemMeta->get_parent_meta_id() ); // true. they are allways set when initialized by calling get_value() on the parent ItemMetadataEntity
|
||||
}
|
||||
|
@ -258,9 +258,9 @@ TODO: document the validation chains
|
|||
|
||||
All validations validate the property with the validation declared in the get_map() method of the repository.
|
||||
|
||||
Validate item -> call ItemMetadata->validate() for each field
|
||||
Validate item -> call ItemMetadata->validate() for each metadatum
|
||||
|
||||
Validate ItemMetadata -> call $fieldType->validate() for the Field type of the field.
|
||||
Validate ItemMetadata -> call $metadatumType->validate() for the Field type of the metadatum.
|
||||
|
||||
Validate Field -> call validate_options() of the Field type
|
||||
|
||||
|
|
|
@ -3,21 +3,21 @@
|
|||
The typical workflow when you create a Digital Repository with Tainacan is:
|
||||
|
||||
* Create a collection
|
||||
* Choose which fields the item in this collections will have
|
||||
* Choose which metadata the item in this collections will have
|
||||
* Choose which filters will be used when browsing the collection
|
||||
* Insert items to the collection or import them from an external source
|
||||
|
||||
## Collections
|
||||
|
||||
A collection is a group of items, that share the same set of fields. Every item uploaded to your digital repository will be part of a collection - and only one collection. For instance, you could have a "paintings" collections, with fields such as Title, Author, Country, Tecnique, etc and another collection for "films", with Title, Director, Country and Genre.
|
||||
A collection is a group of items, that share the same set of metadata. Every item uploaded to your digital repository will be part of a collection - and only one collection. For instance, you could have a "paintings" collections, with metadata such as Title, Author, Country, Tecnique, etc and another collection for "films", with Title, Director, Country and Genre.
|
||||
|
||||
For each collection you can set a different set of fields and they can share common categories, which means you could browse for items in a specific Country, and get both paintings and films in your results.
|
||||
For each collection you can set a different set of metadata and they can share common categories, which means you could browse for items in a specific Country, and get both paintings and films in your results.
|
||||
|
||||
Collections can also have child collections, which will inherit parent's collection fields and can add their own set of additional information.
|
||||
Collections can also have child collections, which will inherit parent's collection metadata and can add their own set of additional information.
|
||||
|
||||
## Items
|
||||
|
||||
Items are the actual content of yout repository. The painting, the film, the book and so on. They belong to a collection and have all the fields configured in the collection it belongs to.
|
||||
Items are the actual content of yout repository. The painting, the film, the book and so on. They belong to a collection and have all the metadata configured in the collection it belongs to.
|
||||
|
||||
In WordPress language, each item is a post and its post type represents its collection.
|
||||
|
||||
|
@ -51,13 +51,13 @@ Metadata Types can be created via plugins and extend the default set of types sh
|
|||
|
||||
## Filters
|
||||
|
||||
For every collection, you may choose which fields will be used to filter the results in a faceted search interface. These are the filters.
|
||||
For every collection, you may choose which metadata will be used to filter the results in a faceted search interface. These are the filters.
|
||||
|
||||
Filters give the ability to the user to filter items in a collection using a Filter Type.
|
||||
|
||||
## Filter Types
|
||||
|
||||
Filter types are the different types of interfaces to filter items in a collections based on one specific Field. Examples of Filter Types are "input text", "datepicker", "date range picker", "number range slider", "list of checkboxes", etc.
|
||||
Filter types are the different types of interfaces to filter items in a collections based on one specific Metadatum. Examples of Filter Types are "input text", "datepicker", "date range picker", "number range slider", "list of checkboxes", etc.
|
||||
|
||||
Each Filter Type object have its own settings and web component that will be used to render the interface.
|
||||
|
||||
|
@ -89,7 +89,7 @@ An item type can be anything. For example, LPs, Books and paintings are õbvious
|
|||
|
||||
Desktop holds items that are not part of any collections yet. You might want to use it when you want to upload a bunch of items and organize them afterwards, instead of having to thinh an prepare all the collections beforehand.
|
||||
|
||||
Items in Desktop are not publicly visible and have only the fields configured in repository level.
|
||||
Items in Desktop are not publicly visible and have only the metadata configured in repository level.
|
||||
|
||||
### Thematic Collections
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Mapping Standards
|
||||
|
||||
Mapping Standards are declarations of standards of metadata. Once they are available and activated in your repository, you can map the fields of your collections to them.
|
||||
Mapping Standards are declarations of standards of metadata. Once they are available and activated in your repository, you can map the metadata of your collections to them.
|
||||
|
||||
## Structure
|
||||
|
||||
|
@ -10,20 +10,20 @@ A Mapping Standard has the following attributes.
|
|||
|
||||
The name of the Mapping Standard.
|
||||
|
||||
### Fields
|
||||
### Metadata
|
||||
|
||||
A list of fields, terms or attributes that this mapping have. These are the element you will be able to map your Collection's Fields.
|
||||
A list of metadata, terms or attributes that this mapping have. These are the element you will be able to map your Collection's Metadata.
|
||||
|
||||
Each field has the following attributes:
|
||||
Each metadatum has the following attributes:
|
||||
|
||||
* Name - The field name, that refers to the name of the attribute in the origin vocabulary or ontology (e.g. title)
|
||||
* Name - The metadatum name, that refers to the name of the attribute in the origin vocabulary or ontology (e.g. title)
|
||||
* Label - The human readable name
|
||||
* URI - The URI of this term/attribute in the origin Ontoloy/Vocabulary
|
||||
|
||||
|
||||
### Allow additional custom fields
|
||||
### Allow additional custom metadata
|
||||
|
||||
Boolen indicating wether this mapping allows additional custom fields to be added.
|
||||
Boolen indicating wether this mapping allows additional custom metadata to be added.
|
||||
|
||||
### Context URL / Vocab URL
|
||||
|
||||
|
@ -38,7 +38,7 @@ The Class of the ontology that this mapping refers to. For example `CreativeWork
|
|||
```
|
||||
{
|
||||
'name': 'Dublin Core',
|
||||
'fields': {
|
||||
'metadata': {
|
||||
{
|
||||
'name': 'title',
|
||||
'label': 'Title',
|
||||
|
@ -59,7 +59,7 @@ The Class of the ontology that this mapping refers to. For example `CreativeWork
|
|||
```
|
||||
{
|
||||
'name': 'Schema.org Creative Works',
|
||||
'fields': {
|
||||
'metadata': {
|
||||
{
|
||||
'name': 'name',
|
||||
'label': 'Name',
|
||||
|
|
|
@ -209,7 +209,7 @@ Allows to view Items marked as private and its items.
|
|||
|
||||
### Categories
|
||||
|
||||
### Fields
|
||||
### Metadata
|
||||
|
||||
### Filters
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ A REST API for Tainacan Plugin. This API uses the Wordpress REST API.
|
|||
|
||||
1. [Collections](#collections)
|
||||
1. [Items](#items)
|
||||
1. [Fields](#fields)
|
||||
1. [Field Types](#field-types)
|
||||
1. [Metadata](#metadata)
|
||||
1. [Metadatum Types](#metadatum-types)
|
||||
1. [Item Metadata](#item-metadata)
|
||||
1. [Taxonomies](#taxonomies)
|
||||
1. [Filters](#filters)
|
||||
|
@ -117,22 +117,22 @@ A REST API for Tainacan Plugin. This API uses the Wordpress REST API.
|
|||
```
|
||||
|
||||
------
|
||||
#### Fields
|
||||
#### Metadata
|
||||
|
||||
1. Route `wp-json/tainacan/v2/collection/(?P<collection_id>[\d]+)/fields`
|
||||
1. Route `wp-json/tainacan/v2/collection/(?P<collection_id>[\d]+)/metadata`
|
||||
|
||||
1. Endpoints:
|
||||
1. GET (Fetch all collection field)
|
||||
1. GET (Fetch all collection metadatum)
|
||||
|
||||
1. POST (Create a field in collection and all it items)
|
||||
1. POST (Create a metadatum in collection and all it items)
|
||||
|
||||
In body of requisition pass a JSON with the attributes of field like:
|
||||
In body of requisition pass a JSON with the attributes of metadatum like:
|
||||
|
||||
```javascript
|
||||
{
|
||||
"name": "string",
|
||||
"description": "string",
|
||||
"field_type": "string",
|
||||
"metadatum_type": "string",
|
||||
"order": "string",
|
||||
"parent": "integer",
|
||||
"required": "string",
|
||||
|
@ -145,15 +145,15 @@ A REST API for Tainacan Plugin. This API uses the Wordpress REST API.
|
|||
}
|
||||
```
|
||||
|
||||
2. Route `wp-json/tainacan/v2/collection/(?P<collection_id>[\d]+)/fields/(?P<field_id>[\d]+)`
|
||||
2. Route `wp-json/tainacan/v2/collection/(?P<collection_id>[\d]+)/metadata/(?P<field_id>[\d]+)`
|
||||
|
||||
1. Endpoints:
|
||||
|
||||
1. GET (Fetch a field from a collection or Fetch all field values)
|
||||
1. GET (Fetch a metadatum from a collection or Fetch all metadatum values)
|
||||
|
||||
To fetch all field values from a field of a collection in all it items, pass a query like `?fetch=all_field_values`
|
||||
To fetch all metadatum values from a metadatum of a collection in all it items, pass a query like `?fetch=all_field_values`
|
||||
|
||||
1. PATCH or PUT (Update a field in a collection and all it items)
|
||||
1. PATCH or PUT (Update a metadatum in a collection and all it items)
|
||||
|
||||
In body of requisition pass a JSON with the attributes you need to update, like:
|
||||
|
||||
|
@ -164,37 +164,37 @@ A REST API for Tainacan Plugin. This API uses the Wordpress REST API.
|
|||
}
|
||||
```
|
||||
|
||||
3. Route `wp-json/tainacan/v2/fields`
|
||||
3. Route `wp-json/tainacan/v2/metadata`
|
||||
|
||||
1. Endpoints:
|
||||
|
||||
1. GET (Fetch all default fields)
|
||||
1. GET (Fetch all default metadata)
|
||||
|
||||
1. POST (Create a default field)
|
||||
1. POST (Create a default metadatum)
|
||||
|
||||
In body of requisition pass a JSON with the attributes of field.
|
||||
In body of requisition pass a JSON with the attributes of metadatum.
|
||||
|
||||
4. Route `wp-json/tainacan/v2/fields/(?P(<field_id>[\d]+))`
|
||||
4. Route `wp-json/tainacan/v2/metadata/(?P(<field_id>[\d]+))`
|
||||
|
||||
1. Endpoints:
|
||||
|
||||
1. DELETE (Trash a default field)
|
||||
1. DELETE (Trash a default metadatum)
|
||||
|
||||
1. PATCH or PUT (Update a default field)
|
||||
1. PATCH or PUT (Update a default metadatum)
|
||||
|
||||
In body of requisition pass a JSON with the attributes you need to update.
|
||||
|
||||
------
|
||||
#### Field Types
|
||||
1. Route `wp-json/tainacan/v2/field-types`
|
||||
#### Metadatum Types
|
||||
1. Route `wp-json/tainacan/v2/metadatum-types`
|
||||
|
||||
1. Endpoint:
|
||||
|
||||
1. GET (Fetch all field types)
|
||||
1. GET (Fetch all metadatum types)
|
||||
------
|
||||
#### Item Metadata
|
||||
|
||||
1. Route `wp-json/tainacan/v2/item/(?P<item_id>[\d]+)/metadata/(?P<metadata_id>[\d]+)`
|
||||
1. Route `wp-json/tainacan/v2/item/(?P<item_id>[\d]+)/metadata/(?P<metadatum_id>[\d]+)`
|
||||
|
||||
1. Endpoints:
|
||||
|
||||
|
@ -271,7 +271,7 @@ A REST API for Tainacan Plugin. This API uses the Wordpress REST API.
|
|||
------
|
||||
#### Filters
|
||||
|
||||
1. Route `wp-json/tainacan/v2/collection/(?P<collection_id>[\d]+)/field/(?P<field_id>[\d]+)/filters`
|
||||
1. Route `wp-json/tainacan/v2/collection/(?P<collection_id>[\d]+)/metadatum/(?P<field_id>[\d]+)/filters`
|
||||
|
||||
1. Endpoints:
|
||||
|
||||
|
@ -317,7 +317,7 @@ A REST API for Tainacan Plugin. This API uses the Wordpress REST API.
|
|||
|
||||
1. GET (Fetch all repository filters)
|
||||
|
||||
1. POST (Create a filter in repository. Without field and collection associations)
|
||||
1. POST (Create a filter in repository. Without metadatum and collection associations)
|
||||
|
||||
Example of JSON passed in body for creating a filter:
|
||||
|
||||
|
@ -338,7 +338,7 @@ A REST API for Tainacan Plugin. This API uses the Wordpress REST API.
|
|||
|
||||
1. GET (Fetch all collection filters)
|
||||
|
||||
1. POST (Create a filter in a collection, without field association)
|
||||
1. POST (Create a filter in a collection, without metadatum association)
|
||||
|
||||
Example of JSON passed in body for creating a filter:
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -132,7 +132,7 @@ class Admin {
|
|||
global $TAINACAN_BASE_URL;
|
||||
|
||||
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
|
||||
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
|
||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
||||
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
|
||||
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
||||
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
|
||||
|
@ -141,7 +141,7 @@ class Admin {
|
|||
|
||||
$entities_labels = [
|
||||
'collections' => $Tainacan_Collections->get_cpt_labels(),
|
||||
'fields' => $Tainacan_Fields->get_cpt_labels(),
|
||||
'metadata' => $Tainacan_Metadata->get_cpt_labels(),
|
||||
'filters' => $Tainacan_Filters->get_cpt_labels(),
|
||||
'items' => $Tainacan_Items->get_cpt_labels(),
|
||||
'taxonomies' => $Tainacan_Taxonomies->get_cpt_labels(),
|
||||
|
@ -183,21 +183,21 @@ class Admin {
|
|||
|
||||
$maps = [
|
||||
'collections' => $Tainacan_Collections->get_map(),
|
||||
'fields' => $Tainacan_Fields->get_map(),
|
||||
'metadata' => $Tainacan_Metadata->get_map(),
|
||||
'filters' => $Tainacan_Filters->get_map(),
|
||||
'items' => $Tainacan_Items->get_map(),
|
||||
'taxonomies' => $Tainacan_Taxonomies->get_map(),
|
||||
];
|
||||
|
||||
$field_types = $Tainacan_Fields->fetch_field_types();
|
||||
$metadatum_types = $Tainacan_Metadata->fetch_metadatum_types();
|
||||
|
||||
foreach( $maps as $type => $map ){
|
||||
foreach ( $map as $field => $details){
|
||||
$settings['i18n']['helpers_label'][$type][$field] = [ 'title' => $details['title'], 'description' => $details['description'] ];
|
||||
foreach ( $map as $metadatum => $details){
|
||||
$settings['i18n']['helpers_label'][$type][$metadatum] = [ 'title' => $details['title'], 'description' => $details['description'] ];
|
||||
}
|
||||
}
|
||||
foreach ( $field_types as $index => $field_type){
|
||||
$class = new $field_type;
|
||||
foreach ( $metadatum_types as $index => $metadatum_type){
|
||||
$class = new $metadatum_type;
|
||||
$settings['i18n']['helpers_label'][$class->get_component()] = $class->get_form_labels();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
<div class="columns is-multiline tnc-advanced-search-container">
|
||||
|
||||
<div
|
||||
v-for="searchField in totalSearchMetadata"
|
||||
:key="searchField"
|
||||
v-for="searchMetadatum in totalSearchMetadata"
|
||||
:key="searchMetadatum"
|
||||
class="field column is-12 tainacan-form">
|
||||
|
||||
<b-field
|
||||
|
@ -12,7 +12,7 @@
|
|||
grouped>
|
||||
<b-field class="column">
|
||||
<b-select
|
||||
@input="addToAdvancedSearchQuery($event, 'field_id', searchField)">
|
||||
@input="addToAdvancedSearchQuery($event, 'field_id', searchMetadatum)">
|
||||
<option
|
||||
v-for="metadata in metadataList"
|
||||
v-if="metadata.enabled"
|
||||
|
@ -24,12 +24,12 @@
|
|||
|
||||
<b-field class="column is-two-thirds">
|
||||
<b-input
|
||||
@input="addValueToAdvancedSearchQuery($event, 'value', searchField)"/>
|
||||
@input="addValueToAdvancedSearchQuery($event, 'value', searchMetadatum)"/>
|
||||
</b-field>
|
||||
|
||||
<b-field class="column">
|
||||
<b-select
|
||||
@input="addToAdvancedSearchQuery($event, 'compare', searchField)">
|
||||
@input="addToAdvancedSearchQuery($event, 'compare', searchMetadatum)">
|
||||
<option
|
||||
v-for="(opt, key) in compare"
|
||||
:value="key"
|
||||
|
@ -52,7 +52,7 @@
|
|||
<a
|
||||
@click="addSearchMetadata"
|
||||
class="is-secondary is-small">
|
||||
{{ $i18n.get('add_more_one_search_field') }}</a>
|
||||
{{ $i18n.get('add_more_one_search_metadatum') }}</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
@ -71,7 +71,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<pre>{{ advancedSearchQuery }}</pre>
|
||||
<!-- <pre>{{ advancedSearchQuery }}</pre> -->
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
|
|
@ -370,38 +370,4 @@
|
|||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
.thumbnail-field {
|
||||
width: 128px;
|
||||
height: 128px;
|
||||
max-width: 128px;
|
||||
max-height: 128px;
|
||||
|
||||
.content {
|
||||
padding: 10px;
|
||||
font-size: 0.8em;
|
||||
}
|
||||
img {
|
||||
bottom: 0;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.thumbnail-buttons-row {
|
||||
display: none;
|
||||
}
|
||||
&:hover {
|
||||
.thumbnail-buttons-row {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
bottom: 31px;
|
||||
background-color: rgba(255,255,255,0.8);
|
||||
padding: 2px 8px;
|
||||
border-radius: 0px 4px 0px 0px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
|
||||
|
|
|
@ -438,8 +438,8 @@ export default {
|
|||
'fetchUsers',
|
||||
'fetchCollectionsForParent'
|
||||
]),
|
||||
...mapActions('fields', [
|
||||
'fetchFields'
|
||||
...mapActions('metadata', [
|
||||
'fetchMetadata'
|
||||
]),
|
||||
onSubmit() {
|
||||
this.isLoading = true;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<label class="label is-inline">
|
||||
{{ $i18n.get('label_name') }}
|
||||
<span
|
||||
class="required-field-asterisk"
|
||||
class="required-metadatum-asterisk"
|
||||
:class="formErrors['name'] != undefined ? 'is-danger' : ''">*</span>
|
||||
<help-button
|
||||
:title="$i18n.getHelperTitle('filters', 'name')"
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<!-- Status -------------------------------- -->
|
||||
<div class="section-label">
|
||||
<label>{{ $i18n.get('label_status') }}</label>
|
||||
<span class="required-field-asterisk">*</span>
|
||||
<span class="required-metadatum-asterisk">*</span>
|
||||
<help-button
|
||||
:title="$i18n.getHelperTitle('items', 'status')"
|
||||
:message="$i18n.getHelperMessage('items', 'status')"/>
|
||||
|
@ -302,7 +302,7 @@
|
|||
<div
|
||||
class="column is-4-5"
|
||||
v-show="!isMetadataColumnCompressed">
|
||||
<label class="section-label">{{ $i18n.get('fields') }}</label>
|
||||
<label class="section-label">{{ $i18n.get('metadata') }}</label>
|
||||
<br>
|
||||
<a
|
||||
class="collapse-all"
|
||||
|
@ -313,12 +313,12 @@
|
|||
:icon=" collapseAll ? 'menu-down' : 'menu-right'" />
|
||||
</a>
|
||||
|
||||
<!-- Fields from Collection-------------------------------- -->
|
||||
<!-- Metadata from Collection-------------------------------- -->
|
||||
<tainacan-form-item
|
||||
v-for="(field, index) of fieldList"
|
||||
v-for="(metadatum, index) of metadatumList"
|
||||
:key="index"
|
||||
:field="field"
|
||||
:is-collapsed="fieldCollapses[index]"
|
||||
:metadatum="metadatum"
|
||||
:is-collapsed="metadatumCollapses[index]"
|
||||
@changeCollapse="onChangeCollapse($event, index)"/>
|
||||
|
||||
</div>
|
||||
|
@ -348,7 +348,7 @@ export default {
|
|||
collectionId: Number,
|
||||
isLoading: false,
|
||||
isMetadataColumnCompressed: false,
|
||||
fieldCollapses: [],
|
||||
metadatumCollapses: [],
|
||||
collapseAll: false,
|
||||
form: {
|
||||
collectionId: Number,
|
||||
|
@ -383,8 +383,8 @@ export default {
|
|||
}
|
||||
},
|
||||
computed: {
|
||||
fieldList() {
|
||||
return JSON.parse(JSON.stringify(this.getFields()));
|
||||
metadatumList() {
|
||||
return JSON.parse(JSON.stringify(this.getMetadata()));
|
||||
},
|
||||
attachmentsList(){
|
||||
return this.getAttachments();
|
||||
|
@ -398,16 +398,16 @@ export default {
|
|||
'sendItem',
|
||||
'updateItem',
|
||||
'updateItemDocument',
|
||||
'fetchFields',
|
||||
'sendField',
|
||||
'fetchMetadata',
|
||||
'sendMetadatum',
|
||||
'fetchItem',
|
||||
'cleanFields',
|
||||
'cleanMetadata',
|
||||
'sendAttachments',
|
||||
'updateThumbnail',
|
||||
'fetchAttachments'
|
||||
]),
|
||||
...mapGetters('item',[
|
||||
'getFields',
|
||||
'getMetadata',
|
||||
'getAttachments'
|
||||
]),
|
||||
onSubmit() {
|
||||
|
@ -431,8 +431,8 @@ export default {
|
|||
})
|
||||
.catch((errors) => {
|
||||
for (let error of errors.errors) {
|
||||
for (let field of Object.keys(error)){
|
||||
eventBus.errors.push({ field_id: field, errors: error[field]});
|
||||
for (let metadatum of Object.keys(error)){
|
||||
eventBus.errors.push({ metadatum_id: metadatum, errors: error[metadatum]});
|
||||
}
|
||||
}
|
||||
this.formErrorMessage = errors.error_message;
|
||||
|
@ -466,11 +466,11 @@ export default {
|
|||
.catch(error => this.$console.error(error));
|
||||
},
|
||||
loadMetadata() {
|
||||
// Obtains Item Field
|
||||
this.fetchFields(this.itemId).then((fields) => {
|
||||
// Obtains Item Metadatum
|
||||
this.fetchMetadata(this.itemId).then((metadata) => {
|
||||
this.isLoading = false;
|
||||
for (let field of fields) {
|
||||
this.fieldCollapses.push(field.field.required == 'yes');
|
||||
for (let metadatum of metadata) {
|
||||
this.metadatumCollapses.push(metadatum.metadatum.required == 'yes');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -492,8 +492,8 @@ export default {
|
|||
})
|
||||
.catch((errors) => {
|
||||
for (let error of errors.errors) {
|
||||
for (let field of Object.keys(error)){
|
||||
eventBus.errors.push({ field_id: field, errors: error[field]});
|
||||
for (let metadatum of Object.keys(error)){
|
||||
eventBus.errors.push({ metadatum_id: metadatum, errors: error[metadatum]});
|
||||
}
|
||||
}
|
||||
this.formErrorMessage = errors.error_message;
|
||||
|
@ -524,8 +524,8 @@ export default {
|
|||
})
|
||||
.catch((errors) => {
|
||||
for (let error of errors.errors) {
|
||||
for (let field of Object.keys(error)){
|
||||
eventBus.errors.push({ field_id: field, errors: error[field]});
|
||||
for (let metadatum of Object.keys(error)){
|
||||
eventBus.errors.push({ metadatum_id: metadatum, errors: error[metadatum]});
|
||||
}
|
||||
}
|
||||
this.formErrorMessage = errors.error_message;
|
||||
|
@ -578,8 +578,8 @@ export default {
|
|||
})
|
||||
.catch((errors) => {
|
||||
for (let error of errors.errors) {
|
||||
for (let field of Object.keys(error)){
|
||||
eventBus.errors.push({ field_id: field, errors: error[field]});
|
||||
for (let metadatum of Object.keys(error)){
|
||||
eventBus.errors.push({ metadatum_id: metadatum, errors: error[metadatum]});
|
||||
}
|
||||
}
|
||||
this.formErrorMessage = errors.error_message;
|
||||
|
@ -623,17 +623,17 @@ export default {
|
|||
toggleCollapseAll() {
|
||||
this.collapseAll = !this.collapseAll;
|
||||
|
||||
for (let i = 0; i < this.fieldCollapses.length; i++)
|
||||
this.fieldCollapses[i] = this.collapseAll;
|
||||
for (let i = 0; i < this.metadatumCollapses.length; i++)
|
||||
this.metadatumCollapses[i] = this.collapseAll;
|
||||
|
||||
},
|
||||
onChangeCollapse(event, index) {
|
||||
this.fieldCollapses.splice(index, 1, event);
|
||||
this.metadatumCollapses.splice(index, 1, event);
|
||||
}
|
||||
},
|
||||
created(){
|
||||
// Obtains collection ID
|
||||
this.cleanFields();
|
||||
this.cleanMetadata();
|
||||
eventBus.clearAllErrors();
|
||||
this.formErrorMessage = '';
|
||||
this.collectionId = this.$route.params.collectionId;
|
||||
|
@ -745,7 +745,7 @@ export default {
|
|||
padding-right: $page-side-padding;
|
||||
transition: all 0.6s;
|
||||
|
||||
.field {
|
||||
.metadatum {
|
||||
padding: 10px 0px 10px 25px;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<form
|
||||
id="fieldEditForm"
|
||||
id="metadatumEditForm"
|
||||
class="tainacan-form"
|
||||
@submit.prevent="saveEdition(editForm)">
|
||||
|
||||
|
@ -11,11 +11,11 @@
|
|||
<label class="label is-inline">
|
||||
{{ $i18n.get('label_name') }}
|
||||
<span
|
||||
class="required-field-asterisk"
|
||||
class="required-metadatum-asterisk"
|
||||
:class="formErrors['name'] != undefined ? 'is-danger' : ''">*</span>
|
||||
<help-button
|
||||
:title="$i18n.getHelperTitle('fields', 'name')"
|
||||
:message="$i18n.getHelperMessage('fields', 'name')"/>
|
||||
:title="$i18n.getHelperTitle('metadata', 'name')"
|
||||
:message="$i18n.getHelperMessage('metadata', 'name')"/>
|
||||
</label>
|
||||
<b-input
|
||||
:class="{'has-content': editForm.name != undefined && editForm.name != ''}"
|
||||
|
@ -31,8 +31,8 @@
|
|||
<label class="label is-inline">
|
||||
{{ $i18n.get('label_description') }}
|
||||
<help-button
|
||||
:title="$i18n.getHelperTitle('fields', 'description')"
|
||||
:message="$i18n.getHelperMessage('fields', 'description')"/>
|
||||
:title="$i18n.getHelperTitle('metadata', 'description')"
|
||||
:message="$i18n.getHelperMessage('metadata', 'description')"/>
|
||||
</label>
|
||||
<b-input
|
||||
:class="{'has-content': editForm.description != undefined && editForm.description != ''}"
|
||||
|
@ -49,8 +49,8 @@
|
|||
<label class="label is-inline">
|
||||
{{ $i18n.get('label_status') }}
|
||||
<help-button
|
||||
:title="$i18n.getHelperTitle('fields', 'status')"
|
||||
:message="$i18n.getHelperMessage('fields', 'status')"/>
|
||||
:title="$i18n.getHelperTitle('metadata', 'status')"
|
||||
:message="$i18n.getHelperMessage('metadata', 'status')"/>
|
||||
</label>
|
||||
<b-field>
|
||||
<b-radio
|
||||
|
@ -84,8 +84,8 @@
|
|||
<label class="label is-inline">
|
||||
{{ $i18n.get('label_display') }}
|
||||
<help-button
|
||||
:title="$i18n.getHelperTitle('fields', 'display')"
|
||||
:message="$i18n.getHelperMessage('fields', 'display')"/>
|
||||
:title="$i18n.getHelperTitle('metadata', 'display')"
|
||||
:message="$i18n.getHelperMessage('metadata', 'display')"/>
|
||||
|
||||
</label>
|
||||
|
||||
|
@ -139,13 +139,13 @@
|
|||
name="required">
|
||||
{{ $i18n.get('label_required') }}
|
||||
<help-button
|
||||
:title="$i18n.getHelperTitle('fields', 'required')"
|
||||
:message="$i18n.getHelperMessage('fields', 'required')"/>
|
||||
:title="$i18n.getHelperTitle('metadata', 'required')"
|
||||
:message="$i18n.getHelperMessage('metadata', 'required')"/>
|
||||
</b-checkbox>
|
||||
</b-field>
|
||||
|
||||
<b-field
|
||||
v-if="!originalField.field_type_object.core"
|
||||
v-if="!originalMetadatum.metadatum_type_object.core"
|
||||
:type="formErrors['multiple'] != undefined ? 'is-danger' : ''"
|
||||
:message="formErrors['multiple'] != undefined ? formErrors['multiple'] : ''">
|
||||
<b-checkbox
|
||||
|
@ -158,8 +158,8 @@
|
|||
name="multiple">
|
||||
{{ $i18n.get('label_allow_multiple') }}
|
||||
<help-button
|
||||
:title="$i18n.getHelperTitle('fields', 'multiple')"
|
||||
:message="$i18n.getHelperMessage('fields', 'multiple')"/>
|
||||
:title="$i18n.getHelperTitle('metadata', 'multiple')"
|
||||
:message="$i18n.getHelperMessage('metadata', 'multiple')"/>
|
||||
</b-checkbox>
|
||||
</b-field>
|
||||
|
||||
|
@ -176,18 +176,18 @@
|
|||
name="collecion_key">
|
||||
{{ $i18n.get('label_unique_value') }}
|
||||
<help-button
|
||||
:title="$i18n.getHelperTitle('fields', 'unique')"
|
||||
:message="$i18n.getHelperMessage('fields', 'unique')"/>
|
||||
:title="$i18n.getHelperTitle('metadata', 'unique')"
|
||||
:message="$i18n.getHelperMessage('metadata', 'unique')"/>
|
||||
</b-checkbox>
|
||||
</b-field>
|
||||
</b-field>
|
||||
|
||||
<component
|
||||
:errors="formErrors['field_type_options']"
|
||||
v-if="(editForm.field_type_object && editForm.field_type_object.form_component) || editForm.edit_form == ''"
|
||||
:is="editForm.field_type_object.form_component"
|
||||
:field="editForm"
|
||||
v-model="editForm.field_type_options"/>
|
||||
:errors="formErrors['metadatum_type_options']"
|
||||
v-if="(editForm.metadatum_type_object && editForm.metadatum_type_object.form_component) || editForm.edit_form == ''"
|
||||
:is="editForm.metadatum_type_object.form_component"
|
||||
:metadatum="editForm"
|
||||
v-model="editForm.metadatum_type_options"/>
|
||||
<div
|
||||
v-html="editForm.edit_form"
|
||||
v-else/>
|
||||
|
@ -216,7 +216,7 @@
|
|||
import {mapActions} from 'vuex';
|
||||
|
||||
export default {
|
||||
name: 'FieldEditionForm',
|
||||
name: 'MetadatumEditionForm',
|
||||
data() {
|
||||
return {
|
||||
editForm: {},
|
||||
|
@ -228,42 +228,42 @@
|
|||
},
|
||||
props: {
|
||||
index: '',
|
||||
editedField: Object,
|
||||
originalField: Object,
|
||||
editedMetadatum: Object,
|
||||
originalMetadatum: Object,
|
||||
isRepositoryLevel: false,
|
||||
collectionId: ''
|
||||
},
|
||||
created() {
|
||||
|
||||
this.editForm = this.editedField;
|
||||
this.editForm = this.editedMetadatum;
|
||||
this.formErrors = this.editForm.formErrors != undefined ? this.editForm.formErrors : {};
|
||||
this.formErrorMessage = this.editForm.formErrors != undefined ? this.editForm.formErrorMessage : '';
|
||||
|
||||
this.oldForm = JSON.parse(JSON.stringify(this.originalField));
|
||||
this.oldForm = JSON.parse(JSON.stringify(this.originalMetadatum));
|
||||
|
||||
},
|
||||
beforeDestroy() {
|
||||
if (this.closedByForm) {
|
||||
this.editedField.saved = true;
|
||||
this.editedMetadatum.saved = true;
|
||||
} else {
|
||||
this.oldForm.saved = this.editForm.saved;
|
||||
if (JSON.stringify(this.editForm) != JSON.stringify(this.oldForm))
|
||||
this.editedField.saved = false;
|
||||
this.editedMetadatum.saved = false;
|
||||
else
|
||||
this.editedField.saved = true;
|
||||
this.editedMetadatum.saved = true;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
...mapActions('fields', [
|
||||
'updateField'
|
||||
...mapActions('metadata', [
|
||||
'updateMetadatum'
|
||||
]),
|
||||
saveEdition(field) {
|
||||
saveEdition(metadatum) {
|
||||
|
||||
if ((field.field_type_object && field.field_type_object.form_component) || field.edit_form == '') {
|
||||
if ((metadatum.metadatum_type_object && metadatum.metadatum_type_object.form_component) || metadatum.edit_form == '') {
|
||||
|
||||
this.updateField({
|
||||
this.updateMetadatum({
|
||||
collectionId: this.collectionId,
|
||||
fieldId: field.id,
|
||||
metadatumId: metadatum.id,
|
||||
isRepositoryLevel: this.isRepositoryLevel,
|
||||
index: this.index,
|
||||
options: this.editForm
|
||||
|
@ -287,16 +287,16 @@
|
|||
this.editForm.formErrorMessage = this.formErrorMessage;
|
||||
});
|
||||
} else {
|
||||
let formElement = document.getElementById('fieldEditForm');
|
||||
let formElement = document.getElementById('metadatumEditForm');
|
||||
let formData = new FormData(formElement);
|
||||
let formObj = {};
|
||||
|
||||
for (let [key, value] of formData.entries())
|
||||
formObj[key] = value;
|
||||
|
||||
this.updateField({
|
||||
this.updateMetadatum({
|
||||
collectionId: this.collectionId,
|
||||
fieldId: field.id,
|
||||
metadatumId: metadatum.id,
|
||||
isRepositoryLevel: this.isRepositoryLevel,
|
||||
index: this.index,
|
||||
options: formObj
|
|
@ -150,8 +150,8 @@
|
|||
})
|
||||
.catch((errors) => {
|
||||
for (let error of errors.errors) {
|
||||
for (let field of Object.keys(error)) {
|
||||
this.$set(this.formErrors, field, (this.formErrors[field] !== undefined ? this.formErrors[field] : '') + error[field] + '\n');
|
||||
for (let metadatum of Object.keys(error)) {
|
||||
this.$set(this.formErrors, metadatum, (this.formErrors[metadatum] !== undefined ? this.formErrors[metadatum] : '') + error[metadatum] + '\n');
|
||||
}
|
||||
}
|
||||
this.$emit('onErrorFound');
|
||||
|
@ -173,8 +173,8 @@
|
|||
})
|
||||
.catch((errors) => {
|
||||
for (let error of errors.errors) {
|
||||
for (let field of Object.keys(error)) {
|
||||
this.$set(this.formErrors, field, (this.formErrors[field] !== undefined ? this.formErrors[field] : '') + error[field] + '\n');
|
||||
for (let metadatum of Object.keys(error)) {
|
||||
this.$set(this.formErrors, metadatum, (this.formErrors[metadatum] !== undefined ? this.formErrors[metadatum] : '') + error[metadatum] + '\n');
|
||||
}
|
||||
}
|
||||
this.$emit('onErrorFound');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<div>
|
||||
<b-loading :active.sync="isLoadingFieldTypes"/>
|
||||
<b-loading :active.sync="isLoadingMetadatumTypes"/>
|
||||
<tainacan-title v-if="!isRepositoryLevel"/>
|
||||
<p v-if="isRepositoryLevel">{{ $i18n.get('info_repository_filters_inheritance') }}</p>
|
||||
<br>
|
||||
|
@ -35,7 +35,7 @@
|
|||
<div
|
||||
class="active-filter-item"
|
||||
:class="{
|
||||
'not-sortable-item': filter.id == undefined || openedFilterId != '' || choosenField.name == filter.name,
|
||||
'not-sortable-item': filter.id == undefined || openedFilterId != '' || choosenMetadatum.name == filter.name,
|
||||
'not-focusable-item': openedFilterId == filter.id,
|
||||
'disabled-filter': filter.enabled == false
|
||||
}"
|
||||
|
@ -84,7 +84,7 @@
|
|||
</a>
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="choosenField.id == filter.id && openedFilterId == ''">
|
||||
<div v-if="choosenMetadatum.id == filter.id && openedFilterId == ''">
|
||||
<form class="tainacan-form">
|
||||
<b-field :label="$i18n.get('label_filter_type')">
|
||||
<b-select
|
||||
|
@ -128,25 +128,25 @@
|
|||
</div>
|
||||
</draggable>
|
||||
</div>
|
||||
<div class="column available-fields-area">
|
||||
<div class="column available-metadata-area">
|
||||
<div class="field" >
|
||||
<h3 class="label"> {{ $i18n.get('label_available_fields') }}</h3>
|
||||
<h3 class="label"> {{ $i18n.get('label_available_metadata') }}</h3>
|
||||
<draggable
|
||||
v-if="availableFieldList.length > 0"
|
||||
v-model="availableFieldList"
|
||||
v-if="availableMetadatumList.length > 0"
|
||||
v-model="availableMetadatumList"
|
||||
:options="{
|
||||
sort: false,
|
||||
group: { name:'filters', pull: true, put: false, revertClone: true },
|
||||
dragClass: 'sortable-drag'
|
||||
}">
|
||||
<div
|
||||
class="available-field-item"
|
||||
v-if="field.enabled"
|
||||
v-for="(field, index) in availableFieldList"
|
||||
class="available-metadatum-item"
|
||||
v-if="metadatum.enabled"
|
||||
v-for="(metadatum, index) in availableMetadatumList"
|
||||
:key="index"
|
||||
@click.prevent="addFieldViaButton(field, index)">
|
||||
@click.prevent="addMetadatumViaButton(metadatum, index)">
|
||||
<grip-icon/>
|
||||
<span class="field-name">{{ field.name }}</span>
|
||||
<span class="metadatum-name">{{ metadatum.name }}</span>
|
||||
</div>
|
||||
</draggable>
|
||||
|
||||
|
@ -159,13 +159,13 @@
|
|||
icon="format-list-checks"
|
||||
size="is-large"/>
|
||||
</p>
|
||||
<p>{{ $i18n.get('info_there_is_no_field' ) }}</p>
|
||||
<p>{{ $i18n.get('info_there_is_no_metadatum' ) }}</p>
|
||||
<router-link
|
||||
id="button-create-field"
|
||||
:to="isRepositoryLevel ? $routerHelper.getNewFieldPath() : $routerHelper.getNewCollectionFieldPath(collectionId)"
|
||||
id="button-create-metadatum"
|
||||
:to="isRepositoryLevel ? $routerHelper.getNewMetadatumPath() : $routerHelper.getNewCollectionMetadatumPath(collectionId)"
|
||||
tag="button"
|
||||
class="button is-secondary is-centered">
|
||||
{{ $i18n.getFrom('fields', 'new_item') }}</router-link>
|
||||
{{ $i18n.getFrom('metadata', 'new_item') }}</router-link>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
@ -187,7 +187,7 @@ export default {
|
|||
collectionId: '',
|
||||
isRepositoryLevel: false,
|
||||
isDraggingFromAvailable: false,
|
||||
isLoadingFieldTypes: true,
|
||||
isLoadingMetadatumTypes: true,
|
||||
isLoadingFilters: false,
|
||||
isLoadingFilterTypes: false,
|
||||
isLoadingFilter: false,
|
||||
|
@ -196,9 +196,9 @@ export default {
|
|||
editForms: {},
|
||||
allowedFilterTypes: [],
|
||||
selectedFilterType: {},
|
||||
choosenField: {},
|
||||
choosenMetadatum: {},
|
||||
newIndex: 0,
|
||||
availableFieldList: [],
|
||||
availableMetadatumList: [],
|
||||
filterTypes: []
|
||||
}
|
||||
},
|
||||
|
@ -255,11 +255,11 @@ export default {
|
|||
'getFilters',
|
||||
'getFilterTypes'
|
||||
]),
|
||||
...mapActions('fields', [
|
||||
'fetchFields',
|
||||
...mapActions('metadata', [
|
||||
'fetchMetadata',
|
||||
]),
|
||||
...mapGetters('fields', [
|
||||
'getFields',
|
||||
...mapGetters('metadata', [
|
||||
'getMetadata',
|
||||
]),
|
||||
handleChange($event) {
|
||||
if ($event.added) {
|
||||
|
@ -278,20 +278,20 @@ export default {
|
|||
}
|
||||
this.updateCollectionFiltersOrder({ collectionId: this.collectionId, filtersOrder: filtersOrder });
|
||||
},
|
||||
updateListOfFields() {
|
||||
updateListOfMetadata() {
|
||||
|
||||
let availableFields = JSON.parse(JSON.stringify(this.getFields())) ;
|
||||
let availableMetadata = JSON.parse(JSON.stringify(this.getMetadata())) ;
|
||||
|
||||
for (let activeFilter of this.activeFilterList) {
|
||||
for (let i = availableFields.length - 1; i >= 0 ; i--) {
|
||||
if (activeFilter.field != undefined) {
|
||||
if (activeFilter.field.field_id == availableFields[i].id)
|
||||
availableFields.splice(i, 1);
|
||||
for (let i = availableMetadata.length - 1; i >= 0 ; i--) {
|
||||
if (activeFilter.metadatum != undefined) {
|
||||
if (activeFilter.metadatum.metadatum_id == availableMetadata[i].id)
|
||||
availableMetadata.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.availableFieldList = availableFields;
|
||||
this.availableMetadatumList = availableMetadata;
|
||||
},
|
||||
onChangeEnable($event, index) {
|
||||
this.activeFilterList[index].enabled = $event;
|
||||
|
@ -301,17 +301,17 @@ export default {
|
|||
}
|
||||
this.updateCollectionFiltersOrder({ collectionId: this.collectionId, filtersOrder: filtersOrder });
|
||||
},
|
||||
addFieldViaButton(fieldType, fieldIndex) {
|
||||
this.availableFieldList.splice(fieldIndex, 1);
|
||||
addMetadatumViaButton(metadatumType, metadatumIndex) {
|
||||
this.availableMetadatumList.splice(metadatumIndex, 1);
|
||||
let lastIndex = this.activeFilterList.length;
|
||||
|
||||
// Updates store with temporary Filter
|
||||
this.addTemporaryFilter(fieldType);
|
||||
this.addTemporaryFilter(metadatumType);
|
||||
|
||||
this.addNewFilter(fieldType, lastIndex);
|
||||
this.addNewFilter(metadatumType, lastIndex);
|
||||
},
|
||||
addNewFilter(choosenField, newIndex) {
|
||||
this.choosenField = choosenField;
|
||||
addNewFilter(choosenMetadatum, newIndex) {
|
||||
this.choosenMetadatum = choosenMetadatum;
|
||||
this.newIndex = newIndex;
|
||||
this.openedFilterId = '';
|
||||
this.allowedFilterTypes = [];
|
||||
|
@ -319,7 +319,7 @@ export default {
|
|||
|
||||
for (let filter of this.filterTypes) {
|
||||
for (let supportedType of filter['supported_types']) {
|
||||
if (choosenField.field_type_object.primitive_type == supportedType)
|
||||
if (choosenMetadatum.metadatum_type_object.primitive_type == supportedType)
|
||||
this.allowedFilterTypes.push(filter);
|
||||
}
|
||||
}
|
||||
|
@ -328,8 +328,8 @@ export default {
|
|||
|
||||
this.sendFilter({
|
||||
collectionId: this.collectionId,
|
||||
fieldId: this.choosenField.id,
|
||||
name: this.choosenField.name,
|
||||
metadatumId: this.choosenMetadatum.id,
|
||||
name: this.choosenMetadatum.name,
|
||||
filterType: this.selectedFilterType.name,
|
||||
status: 'auto-draft',
|
||||
isRepositoryLevel: this.isRepositoryLevel,
|
||||
|
@ -341,7 +341,7 @@ export default {
|
|||
this.updateFiltersOrder();
|
||||
|
||||
this.newIndex = 0;
|
||||
this.choosenField = {};
|
||||
this.choosenMetadatum = {};
|
||||
this.selectedFilterType = {}
|
||||
this.allowedFilterTypes = [];
|
||||
|
||||
|
@ -350,7 +350,7 @@ export default {
|
|||
.catch((error) => {
|
||||
this.$console.error(error);
|
||||
this.newIndex = 0;
|
||||
this.choosenField = {};
|
||||
this.choosenMetadatum = {};
|
||||
this.selectedFilterType = {}
|
||||
this.allowedFilterTypes = [];
|
||||
});
|
||||
|
@ -359,8 +359,8 @@ export default {
|
|||
|
||||
this.deleteFilter(removedFilter.id)
|
||||
.then(() => {
|
||||
// Reload Available Field Types List
|
||||
this.updateListOfFields();
|
||||
// Reload Available Metadatum Types List
|
||||
this.updateListOfMetadata();
|
||||
|
||||
})
|
||||
.catch((error) => { this.$console.log(error)});
|
||||
|
@ -372,8 +372,8 @@ export default {
|
|||
this.createChoosenFilter();
|
||||
},
|
||||
cancelFilterTypeSelection() {
|
||||
this.availableFieldList.push(this.choosenField);
|
||||
this.choosenField = {};
|
||||
this.availableMetadatumList.push(this.choosenMetadatum);
|
||||
this.choosenMetadatum = {};
|
||||
this.allowedFilterTypes = [];
|
||||
this.selectedFilterType = {};
|
||||
this.deleteTemporaryFilter(this.newIndex);
|
||||
|
@ -387,9 +387,9 @@ export default {
|
|||
// Opening collapse
|
||||
} else {
|
||||
|
||||
if (this.openedFilterId == '' && this.choosenField.id != undefined) {
|
||||
this.availableFieldList.push(this.choosenField);
|
||||
this.choosenField = {};
|
||||
if (this.openedFilterId == '' && this.choosenMetadatum.id != undefined) {
|
||||
this.availableMetadatumList.push(this.choosenMetadatum);
|
||||
this.choosenMetadatum = {};
|
||||
this.allowedFilterTypes = [];
|
||||
this.selectedFilterType = {};
|
||||
this.deleteTemporaryFilter(this.newIndex);
|
||||
|
@ -429,7 +429,7 @@ export default {
|
|||
else
|
||||
this.collectionId = this.$route.params.collectionId;
|
||||
|
||||
this.isLoadingFieldTypes = true;
|
||||
this.isLoadingMetadatumTypes = true;
|
||||
this.isLoadingFilters = true;
|
||||
this.isLoadingFilterTypes = true;
|
||||
|
||||
|
@ -445,14 +445,14 @@ export default {
|
|||
this.fetchFilters({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true, includeDisabled: 'yes' })
|
||||
.then(() => {
|
||||
this.isLoadingFilters = false;
|
||||
// Needs to be done after activeFilterList exists to compare and remove chosen fields.
|
||||
this.fetchFields({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true })
|
||||
// Needs to be done after activeFilterList exists to compare and remove chosen metadata.
|
||||
this.fetchMetadata({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true })
|
||||
.then(() => {
|
||||
this.isLoadingFieldTypes = false;
|
||||
this.updateListOfFields();
|
||||
this.isLoadingMetadatumTypes = false;
|
||||
this.updateListOfMetadata();
|
||||
})
|
||||
.catch(() => {
|
||||
this.isLoadingFieldTypes = false;
|
||||
this.isLoadingMetadatumTypes = false;
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
|
@ -589,14 +589,14 @@ export default {
|
|||
&.not-focusable-item, &.not-focusable-item:hover {
|
||||
cursor: default;
|
||||
|
||||
.field-name {
|
||||
.metadatum-name {
|
||||
color: $secondary;
|
||||
}
|
||||
.handle .label-details, .handle .icon {
|
||||
color: $gray !important;
|
||||
}
|
||||
}
|
||||
&.disabled-field {
|
||||
&.disabled-metadatum {
|
||||
color: $gray;
|
||||
}
|
||||
}
|
||||
|
@ -645,7 +645,7 @@ export default {
|
|||
}
|
||||
}
|
||||
|
||||
.available-fields-area {
|
||||
.available-metadata-area {
|
||||
padding: 10px 0px 10px 10px;
|
||||
margin: 0;
|
||||
max-width: 280px;
|
||||
|
@ -657,8 +657,8 @@ export default {
|
|||
h3 {
|
||||
margin: 1em 0em 1em 0em !important;
|
||||
}
|
||||
.available-field-item::before,
|
||||
.available-field-item::after {
|
||||
.available-metadatum-item::before,
|
||||
.available-metadatum-item::after {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
|
@ -669,7 +669,7 @@ export default {
|
|||
font-weight: 500;
|
||||
}
|
||||
|
||||
.available-field-item {
|
||||
.available-metadatum-item {
|
||||
padding: 0.7em;
|
||||
margin: 4px;
|
||||
background-color: white;
|
||||
|
@ -692,7 +692,7 @@ export default {
|
|||
position: relative;
|
||||
bottom: 3px;
|
||||
}
|
||||
.field-name {
|
||||
.metadatum-name {
|
||||
text-overflow: ellipsis;
|
||||
overflow-x: hidden;
|
||||
white-space: nowrap;
|
||||
|
@ -731,7 +731,7 @@ export default {
|
|||
.sortable-drag {
|
||||
opacity: 1 !important;
|
||||
}
|
||||
.available-field-item:hover {
|
||||
.available-metadatum-item:hover {
|
||||
background-color: $secondary;
|
||||
border-color: $secondary;
|
||||
color: white;
|
||||
|
|
|
@ -57,9 +57,9 @@
|
|||
|
||||
<!-- Title -->
|
||||
<p
|
||||
v-for="(column, index) in tableFields"
|
||||
v-for="(column, index) in tableMetadata"
|
||||
:key="index"
|
||||
v-if="column.display && column.field_type_object != undefined && (column.field_type_object.related_mapped_prop == 'title')"
|
||||
v-if="column.display && column.metadatum_type_object != undefined && (column.metadatum_type_object.related_mapped_prop == 'title')"
|
||||
class="metadata-title"
|
||||
@click="goToItemPage(item)"
|
||||
v-html="item.metadata != undefined ? renderMetadata(item.metadata, column) : ''"/>
|
||||
|
@ -118,9 +118,9 @@
|
|||
|
||||
<!-- Title -->
|
||||
<p
|
||||
v-for="(column, index) in tableFields"
|
||||
v-for="(column, index) in tableMetadata"
|
||||
:key="index"
|
||||
v-if="column.display && column.field_type_object != undefined && (column.field_type_object.related_mapped_prop == 'title')"
|
||||
v-if="column.display && column.metadatum_type_object != undefined && (column.metadatum_type_object.related_mapped_prop == 'title')"
|
||||
class="metadata-title"
|
||||
@click="goToItemPage(item)"
|
||||
v-html="item.metadata != undefined ? renderMetadata(item.metadata, column) : ''" />
|
||||
|
@ -160,9 +160,9 @@
|
|||
|
||||
<div class="list-metadata media-body">
|
||||
<span
|
||||
v-for="(column, index) in tableFields"
|
||||
v-for="(column, index) in tableMetadata"
|
||||
:key="index"
|
||||
v-if="column.display && column.slug != 'thumbnail' && column.field_type_object != undefined && (column.field_type_object.related_mapped_prop != 'title')">
|
||||
v-if="column.display && column.slug != 'thumbnail' && column.metadatum_type_object != undefined && (column.metadatum_type_object.related_mapped_prop != 'title')">
|
||||
<h3 class="metadata-label">{{ column.name }}</h3>
|
||||
<p
|
||||
v-html="item.metadata != undefined ? renderMetadata(item.metadata, column) : ''"
|
||||
|
@ -185,17 +185,17 @@
|
|||
|
||||
<!-- nothing to show on header for checkboxes -->
|
||||
</th>
|
||||
<!-- Displayed Fields -->
|
||||
<!-- Displayed Metadata -->
|
||||
<th
|
||||
v-for="(column, index) in tableFields"
|
||||
v-for="(column, index) in tableMetadata"
|
||||
:key="index"
|
||||
v-if="column.display"
|
||||
class="column-default-width"
|
||||
:class="{
|
||||
'thumbnail-cell': column.field == 'row_thumbnail',
|
||||
'column-small-width' : column.field_type_object != undefined ? (column.field_type_object.className == 'Tainacan\\Field_Types\\Date' || column.field_type_object.className == 'Tainacan\\Field_Types\\Numeric') : false,
|
||||
'column-medium-width' : column.field_type_object != undefined ? (column.field_type_object.className == 'Tainacan\\Field_Types\\Selectbox' || column.field_type_object.className == 'Tainacan\\Field_Types\\Category' || column.field_type_object.className == 'Tainacan\\Field_Types\\Compound') : false,
|
||||
'column-large-width' : column.field_type_object != undefined ? (column.field_type_object.className == 'Tainacan\\Field_Types\\Textarea') : false,
|
||||
'thumbnail-cell': column.metadatum == 'row_thumbnail',
|
||||
'column-small-width' : column.metadatum_type_object != undefined ? (column.metadatum_type_object.className == 'Tainacan\\Metadatum_Types\\Date' || column.metadatum_type_object.className == 'Tainacan\\Metadatum_Types\\Numeric') : false,
|
||||
'column-medium-width' : column.metadatum_type_object != undefined ? (column.metadatum_type_object.className == 'Tainacan\\Metadatum_Types\\Selectbox' || column.metadatum_type_object.className == 'Tainacan\\Metadatum_Types\\Category' || column.metadatum_type_object.className == 'Tainacan\\Metadatum_Types\\Compound') : false,
|
||||
'column-large-width' : column.metadatum_type_object != undefined ? (column.metadatum_type_object.className == 'Tainacan\\Metadatum_Types\\Textarea') : false,
|
||||
}"
|
||||
:custom-key="column.slug">
|
||||
<div class="th-wrap">{{ column.name }}</div>
|
||||
|
@ -223,24 +223,24 @@
|
|||
<!-- Item Displayed Metadata -->
|
||||
<td
|
||||
:key="index"
|
||||
v-for="(column, index) in tableFields"
|
||||
v-for="(column, index) in tableMetadata"
|
||||
v-if="column.display"
|
||||
:label="column.name"
|
||||
class="column-default-width"
|
||||
:class="{
|
||||
'thumbnail-cell': column.field == 'row_thumbnail',
|
||||
'column-main-content' : column.field_type_object != undefined ? (column.field_type_object.related_mapped_prop == 'title') : false,
|
||||
'column-needed-width column-align-right' : column.field_type_object != undefined ? (column.field_type_object.className == 'Tainacan\\Field_Types\\Numeric') : false,
|
||||
'column-small-width' : column.field_type_object != undefined ? (column.field_type_object.className == 'Tainacan\\Field_Types\\Date' || column.field_type_object.className == 'Tainacan\\Field_Types\\Numeric') : false,
|
||||
'column-medium-width' : column.field_type_object != undefined ? (column.field_type_object.className == 'Tainacan\\Field_Types\\Selectbox' || column.field_type_object.className == 'Tainacan\\Field_Types\\Category' || column.field_type_object.className == 'Tainacan\\Field_Types\\Compound') : false,
|
||||
'column-large-width' : column.field_type_object != undefined ? (column.field_type_object.className == 'Tainacan\\Field_Types\\Textarea') : false,
|
||||
'thumbnail-cell': column.metadatum == 'row_thumbnail',
|
||||
'column-main-content' : column.metadatum_type_object != undefined ? (column.metadatum_type_object.related_mapped_prop == 'title') : false,
|
||||
'column-needed-width column-align-right' : column.metadatum_type_object != undefined ? (column.metadatum_type_object.className == 'Tainacan\\Metadatum_Types\\Numeric') : false,
|
||||
'column-small-width' : column.metadatum_type_object != undefined ? (column.metadatum_type_object.className == 'Tainacan\\Metadatum_Types\\Date' || column.metadatum_type_object.className == 'Tainacan\\Metadatum_Types\\Numeric') : false,
|
||||
'column-medium-width' : column.metadatum_type_object != undefined ? (column.metadatum_type_object.className == 'Tainacan\\Metadatum_Types\\Selectbox' || column.metadatum_type_object.className == 'Tainacan\\Metadatum_Types\\Category' || column.metadatum_type_object.className == 'Tainacan\\Metadatum_Types\\Compound') : false,
|
||||
'column-large-width' : column.metadatum_type_object != undefined ? (column.metadatum_type_object.className == 'Tainacan\\Metadatum_Types\\Textarea') : false,
|
||||
}"
|
||||
@click="goToItemPage(item)">
|
||||
|
||||
<!-- <data-and-tooltip
|
||||
v-if="column.field !== 'row_thumbnail' &&
|
||||
column.field !== 'row_actions' &&
|
||||
column.field !== 'row_creation'"
|
||||
v-if="column.metadatum !== 'row_thumbnail' &&
|
||||
column.metadatum !== 'row_actions' &&
|
||||
column.metadatum !== 'row_creation'"
|
||||
:data="renderMetadata(item.metadata, column)"/> -->
|
||||
<p
|
||||
v-tooltip="{
|
||||
|
@ -250,13 +250,13 @@
|
|||
placement: 'auto-start'
|
||||
}"
|
||||
v-if="item.metadata != undefined &&
|
||||
column.field !== 'row_thumbnail' &&
|
||||
column.field !== 'row_actions' &&
|
||||
column.field !== 'row_creation' &&
|
||||
column.field !== 'row_author'"
|
||||
column.metadatum !== 'row_thumbnail' &&
|
||||
column.metadatum !== 'row_actions' &&
|
||||
column.metadatum !== 'row_creation' &&
|
||||
column.metadatum !== 'row_author'"
|
||||
v-html="renderMetadata(item.metadata, column)"/>
|
||||
|
||||
<span v-if="column.field == 'row_thumbnail'">
|
||||
<span v-if="column.metadatum == 'row_thumbnail'">
|
||||
<img
|
||||
class="table-thumb"
|
||||
:src="item['thumbnail'].thumb ? item['thumbnail'].thumb : thumbPlaceholderPath">
|
||||
|
@ -268,7 +268,7 @@
|
|||
autoHide: false,
|
||||
placement: 'auto-start'
|
||||
}"
|
||||
v-if="column.field == 'row_author' || column.field == 'row_creation'">
|
||||
v-if="column.metadatum == 'row_author' || column.metadatum == 'row_creation'">
|
||||
{{ item[column.slug] }}
|
||||
</p>
|
||||
|
||||
|
@ -321,7 +321,7 @@ export default {
|
|||
},
|
||||
props: {
|
||||
collectionId: Number,
|
||||
tableFields: Array,
|
||||
tableMetadata: Array,
|
||||
items: Array,
|
||||
isLoading: false,
|
||||
isOnTrash: false,
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
<template>
|
||||
<div>
|
||||
<b-loading :active.sync="isLoadingFieldTypes"/>
|
||||
<b-loading :active.sync="isLoadingMetadatumTypes"/>
|
||||
<tainacan-title v-if="!isRepositoryLevel"/>
|
||||
<p v-if="isRepositoryLevel">{{ $i18n.get('info_repository_metadata_inheritance') }}</p>
|
||||
<br>
|
||||
<b-tabs v-model="activeTab">
|
||||
<b-tab-item :label="$i18n.get('fields')">
|
||||
<b-tab-item :label="$i18n.get('metadata')">
|
||||
<div class="columns">
|
||||
<div class="column">
|
||||
<section
|
||||
v-if="activeFieldList.length <= 0 && !isLoadingFields"
|
||||
v-if="activeMetadatumList.length <= 0 && !isLoadingMetadata"
|
||||
class="field is-grouped-centered section">
|
||||
<div class="content has-text-gray has-text-centered">
|
||||
<p>
|
||||
|
@ -17,120 +17,120 @@
|
|||
icon="format-list-bulleted-type"
|
||||
size="is-large"/>
|
||||
</p>
|
||||
<p>{{ $i18n.get('info_there_is_no_field' ) }}</p>
|
||||
<p>{{ $i18n.get('info_there_is_no_metadatum' ) }}</p>
|
||||
<p>{{ $i18n.get('info_create_metadata' ) }}</p>
|
||||
</div>
|
||||
</section>
|
||||
<draggable
|
||||
v-model="activeFieldList"
|
||||
class="active-fields-area"
|
||||
v-model="activeMetadatumList"
|
||||
class="active-metadata-area"
|
||||
@change="handleChange"
|
||||
:class="{'fields-area-receive': isDraggingFromAvailable}"
|
||||
:class="{'metadata-area-receive': isDraggingFromAvailable}"
|
||||
:options="{
|
||||
group: { name:'fields', pull: false, put: true },
|
||||
sort: openedFieldId == '' || openedFieldId == undefined,
|
||||
//disabled: openedFieldId != '' && openedFieldId != undefined,
|
||||
group: { name:'metadata', pull: false, put: true },
|
||||
sort: openedMetadatumId == '' || openedMetadatumId == undefined,
|
||||
//disabled: openedMetadatumId != '' && openedMetadatumId != undefined,
|
||||
handle: '.handle',
|
||||
ghostClass: 'sortable-ghost',
|
||||
chosenClass: 'sortable-chosen',
|
||||
filter: 'not-sortable-item',
|
||||
animation: '250'}">
|
||||
<div
|
||||
class="active-field-item"
|
||||
class="active-metadatum-item"
|
||||
:class="{
|
||||
'not-sortable-item': field.id == undefined || openedFieldId != '' ,
|
||||
'not-focusable-item': openedFieldId == field.id,
|
||||
'disabled-field': field.enabled == false
|
||||
'not-sortable-item': metadatum.id == undefined || openedMetadatumId != '' ,
|
||||
'not-focusable-item': openedMetadatumId == metadatum.id,
|
||||
'disabled-metadatum': metadatum.enabled == false
|
||||
}"
|
||||
v-for="(field, index) in activeFieldList"
|
||||
v-for="(metadatum, index) in activeMetadatumList"
|
||||
:key="index">
|
||||
<div class="handle">
|
||||
<grip-icon/>
|
||||
<span
|
||||
class="field-name"
|
||||
:class="{'is-danger': formWithErrors == field.id }">
|
||||
{{ field.name }}
|
||||
class="metadatum-name"
|
||||
:class="{'is-danger': formWithErrors == metadatum.id }">
|
||||
{{ metadatum.name }}
|
||||
</span>
|
||||
<span
|
||||
v-if="field.id != undefined"
|
||||
v-if="metadatum.id != undefined"
|
||||
class="label-details">
|
||||
({{ $i18n.get(field.field_type_object.component) }}) <em>{{ (field.collection_id != collectionId) ? $i18n.get('label_inherited') : '' }}</em>
|
||||
({{ $i18n.get(metadatum.metadatum_type_object.component) }}) <em>{{ (metadatum.collection_id != collectionId) ? $i18n.get('label_inherited') : '' }}</em>
|
||||
<span
|
||||
class="not-saved"
|
||||
v-if="(editForms[field.id] != undefined && editForms[field.id].saved != true) || field.status == 'auto-draft'">
|
||||
v-if="(editForms[metadatum.id] != undefined && editForms[metadatum.id].saved != true) || metadatum.status == 'auto-draft'">
|
||||
{{ $i18n.get('info_not_saved') }}
|
||||
</span>
|
||||
</span>
|
||||
<span
|
||||
class="loading-spinner"
|
||||
v-if="field.id == undefined"/>
|
||||
v-if="metadatum.id == undefined"/>
|
||||
<span
|
||||
class="controls"
|
||||
v-if="field.id !== undefined">
|
||||
v-if="metadatum.id !== undefined">
|
||||
<b-switch
|
||||
size="is-small"
|
||||
v-model="field.enabled"
|
||||
v-model="metadatum.enabled"
|
||||
@input="onChangeEnable($event, index)"/>
|
||||
<a
|
||||
:style="{ visibility:
|
||||
field.collection_id != collectionId
|
||||
metadatum.collection_id != collectionId
|
||||
? 'hidden' : 'visible'
|
||||
}"
|
||||
@click.prevent="editField(field)">
|
||||
@click.prevent="editMetadatum(metadatum)">
|
||||
<b-icon
|
||||
type="is-gray"
|
||||
icon="pencil"/>
|
||||
</a>
|
||||
<a
|
||||
:style="{ visibility:
|
||||
field.collection_id != collectionId ||
|
||||
field.field_type == 'Tainacan\\Field_Types\\Core_Title' ||
|
||||
field.field_type == 'Tainacan\\Field_Types\\Core_Description'
|
||||
metadatum.collection_id != collectionId ||
|
||||
metadatum.metadatum_type == 'Tainacan\\Metadatum_Types\\Core_Title' ||
|
||||
metadatum.metadatum_type == 'Tainacan\\Metadatum_Types\\Core_Description'
|
||||
? 'hidden' : 'visible'
|
||||
}"
|
||||
@click.prevent="removeField(field)">
|
||||
@click.prevent="removeMetadatum(metadatum)">
|
||||
<b-icon
|
||||
type="is-gray"
|
||||
icon="delete"/>
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="openedFieldId == field.id">
|
||||
<field-edition-form
|
||||
<div v-if="openedMetadatumId == metadatum.id">
|
||||
<metadatum-edition-form
|
||||
:collection-id="collectionId"
|
||||
:is-repository-level="isRepositoryLevel"
|
||||
@onEditionFinished="onEditionFinished()"
|
||||
@onEditionCanceled="onEditionCanceled()"
|
||||
@onErrorFound="formWithErrors = field.id"
|
||||
@onErrorFound="formWithErrors = metadatum.id"
|
||||
:index="index"
|
||||
:original-field="field"
|
||||
:edited-field="editForms[field.id]"/>
|
||||
:original-metadatum="metadatum"
|
||||
:edited-metadatum="editForms[metadatum.id]"/>
|
||||
</div>
|
||||
</div>
|
||||
</draggable>
|
||||
</div>
|
||||
|
||||
<div class="column available-fields-area" >
|
||||
<div class="column available-metadata-area" >
|
||||
<div class="field">
|
||||
<h3 class="label">{{ $i18n.get('label_available_field_types') }}</h3>
|
||||
<h3 class="label">{{ $i18n.get('label_available_metadatum_types') }}</h3>
|
||||
<draggable
|
||||
v-model="availableFieldList"
|
||||
v-model="availableMetadatumList"
|
||||
:options="{
|
||||
sort: false,
|
||||
group: { name:'fields', pull: 'clone', put: false, revertClone: true },
|
||||
group: { name:'metadata', pull: 'clone', put: false, revertClone: true },
|
||||
dragClass: 'sortable-drag'
|
||||
}">
|
||||
<div
|
||||
@click.prevent="addFieldViaButton(field)"
|
||||
class="available-field-item"
|
||||
:class="{ 'hightlighted-field' : hightlightedField == field.name }"
|
||||
v-for="(field, index) in availableFieldList"
|
||||
@click.prevent="addMetadatumViaButton(metadatum)"
|
||||
class="available-metadatum-item"
|
||||
:class="{ 'hightlighted-metadatum' : hightlightedMetadatum == metadatum.name }"
|
||||
v-for="(metadatum, index) in availableMetadatumList"
|
||||
:key="index">
|
||||
<grip-icon/>
|
||||
<span class="field-name">{{ field.name }}</span>
|
||||
<span class="metadatum-name">{{ metadatum.name }}</span>
|
||||
<span
|
||||
class="loading-spinner"
|
||||
v-if="hightlightedField == field.name"/>
|
||||
v-if="hightlightedMetadatum == metadatum.name"/>
|
||||
</div>
|
||||
</draggable>
|
||||
</div>
|
||||
|
@ -148,44 +148,44 @@
|
|||
<script>
|
||||
import { mapActions, mapGetters } from 'vuex';
|
||||
import GripIcon from '../other/grip-icon.vue';
|
||||
import FieldEditionForm from './../edition/field-edition-form.vue';
|
||||
import MetadatumEditionForm from './../edition/metadatum-edition-form.vue';
|
||||
import CustomDialog from '../other/custom-dialog.vue';
|
||||
|
||||
export default {
|
||||
name: 'FieldsList',
|
||||
name: 'MetadataList',
|
||||
data(){
|
||||
return {
|
||||
collectionId: '',
|
||||
isRepositoryLevel: false,
|
||||
isDraggingFromAvailable: false,
|
||||
isLoadingFieldTypes: true,
|
||||
isLoadingFields: false,
|
||||
isLoadingField: false,
|
||||
openedFieldId: '',
|
||||
isLoadingMetadatumTypes: true,
|
||||
isLoadingMetadata: false,
|
||||
isLoadingMetadatum: false,
|
||||
openedMetadatumId: '',
|
||||
formWithErrors: '',
|
||||
hightlightedField: '',
|
||||
hightlightedMetadatum: '',
|
||||
editForms: {}
|
||||
}
|
||||
},
|
||||
components: {
|
||||
FieldEditionForm,
|
||||
MetadatumEditionForm,
|
||||
GripIcon
|
||||
},
|
||||
computed: {
|
||||
availableFieldList: {
|
||||
availableMetadatumList: {
|
||||
get() {
|
||||
return this.getFieldTypes();
|
||||
return this.getMetadatumTypes();
|
||||
},
|
||||
set(value) {
|
||||
return this.updateFieldTypes(value);
|
||||
return this.updateMetadatumTypes(value);
|
||||
}
|
||||
},
|
||||
activeFieldList: {
|
||||
activeMetadatumList: {
|
||||
get() {
|
||||
return this.getFields();
|
||||
return this.getMetadata();
|
||||
},
|
||||
set(value) {
|
||||
this.updateFields(value);
|
||||
this.updateMetadata(value);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -195,14 +195,14 @@ export default {
|
|||
if (!this.editForms[editForm].saved)
|
||||
hasUnsavedForms = true;
|
||||
}
|
||||
if ((this.openedFieldId != '' && this.openedFieldId != undefined) || hasUnsavedForms ) {
|
||||
if ((this.openedMetadatumId != '' && this.openedMetadatumId != undefined) || hasUnsavedForms ) {
|
||||
this.$modal.open({
|
||||
parent: this,
|
||||
component: CustomDialog,
|
||||
props: {
|
||||
icon: 'alert',
|
||||
title: this.$i18n.get('label_warning'),
|
||||
message: this.$i18n.get('info_warning_fields_not_saved'),
|
||||
message: this.$i18n.get('info_warning_metadata_not_saved'),
|
||||
onConfirm: () => {
|
||||
this.onEditionCanceled();
|
||||
next();
|
||||
|
@ -214,133 +214,133 @@ export default {
|
|||
}
|
||||
},
|
||||
methods: {
|
||||
...mapActions('fields', [
|
||||
'fetchFieldTypes',
|
||||
'updateFieldTypes',
|
||||
'fetchFields',
|
||||
'sendField',
|
||||
'deleteField',
|
||||
'updateFields',
|
||||
'updateCollectionFieldsOrder'
|
||||
...mapActions('metadata', [
|
||||
'fetchMetadatumTypes',
|
||||
'updateMetadatumTypes',
|
||||
'fetchMetadata',
|
||||
'sendMetadatum',
|
||||
'deleteMetadatum',
|
||||
'updateMetadata',
|
||||
'updateCollectionMetadataOrder'
|
||||
]),
|
||||
...mapGetters('fields',[
|
||||
'getFieldTypes',
|
||||
'getFields'
|
||||
...mapGetters('metadata',[
|
||||
'getMetadatumTypes',
|
||||
'getMetadata'
|
||||
]),
|
||||
handleChange(event) {
|
||||
if (event.added) {
|
||||
this.addNewField(event.added.element, event.added.newIndex);
|
||||
this.addNewMetadatum(event.added.element, event.added.newIndex);
|
||||
} else if (event.removed) {
|
||||
this.removeField(event.removed.element);
|
||||
this.removeMetadatum(event.removed.element);
|
||||
} else if (event.moved) {
|
||||
if (!this.isRepositoryLevel)
|
||||
this.updateFieldsOrder();
|
||||
this.updateMetadataOrder();
|
||||
}
|
||||
},
|
||||
updateFieldsOrder() {
|
||||
let fieldsOrder = [];
|
||||
for (let field of this.activeFieldList) {
|
||||
fieldsOrder.push({'id': field.id, 'enabled': field.enabled});
|
||||
updateMetadataOrder() {
|
||||
let metadataOrder = [];
|
||||
for (let metadatum of this.activeMetadatumList) {
|
||||
metadataOrder.push({'id': metadatum.id, 'enabled': metadatum.enabled});
|
||||
}
|
||||
this.updateCollectionFieldsOrder({ collectionId: this.collectionId, fieldsOrder: fieldsOrder });
|
||||
this.updateCollectionMetadataOrder({ collectionId: this.collectionId, metadataOrder: metadataOrder });
|
||||
},
|
||||
onChangeEnable($event, index) {
|
||||
this.activeFieldList[index].enabled = $event;
|
||||
let fieldsOrder = [];
|
||||
for (let field of this.activeFieldList) {
|
||||
fieldsOrder.push({'id': field.id, 'enabled': field.enabled});
|
||||
this.activeMetadatumList[index].enabled = $event;
|
||||
let metadataOrder = [];
|
||||
for (let metadatum of this.activeMetadatumList) {
|
||||
metadataOrder.push({'id': metadatum.id, 'enabled': metadatum.enabled});
|
||||
}
|
||||
this.updateCollectionFieldsOrder({ collectionId: this.collectionId, fieldsOrder: fieldsOrder });
|
||||
this.updateCollectionMetadataOrder({ collectionId: this.collectionId, metadataOrder: metadataOrder });
|
||||
},
|
||||
addFieldViaButton(fieldType) {
|
||||
let lastIndex = this.activeFieldList.length;
|
||||
this.addNewField(fieldType, lastIndex);
|
||||
addMetadatumViaButton(metadatumType) {
|
||||
let lastIndex = this.activeMetadatumList.length;
|
||||
this.addNewMetadatum(metadatumType, lastIndex);
|
||||
|
||||
// Higlights the clicker field
|
||||
this.hightlightedField = fieldType.name;
|
||||
// Higlights the clicker metadatum
|
||||
this.hightlightedMetadatum = metadatumType.name;
|
||||
|
||||
},
|
||||
addNewField(newField, newIndex) {
|
||||
this.sendField({collectionId: this.collectionId, name: newField.name, fieldType: newField.className, status: 'auto-draft', isRepositoryLevel: this.isRepositoryLevel, newIndex: newIndex})
|
||||
.then((field) => {
|
||||
addNewMetadatum(newMetadatum, newIndex) {
|
||||
this.sendMetadatum({collectionId: this.collectionId, name: newMetadatum.name, metadatumType: newMetadatum.className, status: 'auto-draft', isRepositoryLevel: this.isRepositoryLevel, newIndex: newIndex})
|
||||
.then((metadatum) => {
|
||||
|
||||
if (!this.isRepositoryLevel)
|
||||
this.updateFieldsOrder();
|
||||
this.updateMetadataOrder();
|
||||
|
||||
this.editField(field);
|
||||
this.hightlightedField = '';
|
||||
this.editMetadatum(metadatum);
|
||||
this.hightlightedMetadatum = '';
|
||||
})
|
||||
.catch((error) => {
|
||||
this.$console.error(error);
|
||||
});
|
||||
},
|
||||
removeField(removedField) {
|
||||
this.deleteField({ collectionId: this.collectionId, fieldId: removedField.id, isRepositoryLevel: this.isRepositoryLevel})
|
||||
removeMetadatum(removedMetadatum) {
|
||||
this.deleteMetadatum({ collectionId: this.collectionId, metadatumId: removedMetadatum.id, isRepositoryLevel: this.isRepositoryLevel})
|
||||
.then(() => {
|
||||
if (!this.isRepositoryLevel)
|
||||
this.updateFieldsOrder();
|
||||
this.updateMetadataOrder();
|
||||
})
|
||||
.catch(() => {
|
||||
});
|
||||
},
|
||||
editField(field) {
|
||||
editMetadatum(metadatum) {
|
||||
// Closing collapse
|
||||
if (this.openedFieldId == field.id) {
|
||||
this.openedFieldId = '';
|
||||
if (this.openedMetadatumId == metadatum.id) {
|
||||
this.openedMetadatumId = '';
|
||||
|
||||
// Opening collapse
|
||||
} else {
|
||||
|
||||
this.openedFieldId = field.id;
|
||||
this.openedMetadatumId = metadatum.id;
|
||||
// First time opening
|
||||
if (this.editForms[this.openedFieldId] == undefined) {
|
||||
this.editForms[this.openedFieldId] = JSON.parse(JSON.stringify(field));
|
||||
this.editForms[this.openedFieldId].saved = true;
|
||||
if (this.editForms[this.openedMetadatumId] == undefined) {
|
||||
this.editForms[this.openedMetadatumId] = JSON.parse(JSON.stringify(metadatum));
|
||||
this.editForms[this.openedMetadatumId].saved = true;
|
||||
|
||||
// Field inserted now
|
||||
if (this.editForms[this.openedFieldId].status == 'auto-draft') {
|
||||
this.editForms[this.openedFieldId].status = 'publish';
|
||||
this.editForms[this.openedFieldId].saved = false;
|
||||
// Metadatum inserted now
|
||||
if (this.editForms[this.openedMetadatumId].status == 'auto-draft') {
|
||||
this.editForms[this.openedMetadatumId].status = 'publish';
|
||||
this.editForms[this.openedMetadatumId].saved = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
onEditionFinished() {
|
||||
this.formWithErrors = '';
|
||||
delete this.editForms[this.openedFieldId];
|
||||
this.openedFieldId = '';
|
||||
delete this.editForms[this.openedMetadatumId];
|
||||
this.openedMetadatumId = '';
|
||||
},
|
||||
onEditionCanceled() {
|
||||
this.formWithErrors = '';
|
||||
delete this.editForms[this.openedFieldId];
|
||||
this.openedFieldId = '';
|
||||
delete this.editForms[this.openedMetadatumId];
|
||||
this.openedMetadatumId = '';
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.isLoadingFieldTypes = true;
|
||||
this.isLoadingFields = true;
|
||||
this.isLoadingMetadatumTypes = true;
|
||||
this.isLoadingMetadata = true;
|
||||
|
||||
this.fetchFieldTypes()
|
||||
this.fetchMetadatumTypes()
|
||||
.then(() => {
|
||||
this.isLoadingFieldTypes = false;
|
||||
this.isLoadingMetadatumTypes = false;
|
||||
})
|
||||
.catch(() => {
|
||||
this.isLoadingFieldTypes = false;
|
||||
this.isLoadingMetadatumTypes = false;
|
||||
});
|
||||
|
||||
this.isRepositoryLevel = this.$route.name == 'FieldsPage' ? true : false;
|
||||
this.isRepositoryLevel = this.$route.name == 'MetadataPage' ? true : false;
|
||||
if (this.isRepositoryLevel)
|
||||
this.collectionId = 'default';
|
||||
else
|
||||
this.collectionId = this.$route.params.collectionId;
|
||||
|
||||
|
||||
this.fetchFields({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true})
|
||||
this.fetchMetadata({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true})
|
||||
.then(() => {
|
||||
this.isLoadingFields = false;
|
||||
this.isLoadingMetadata = false;
|
||||
})
|
||||
.catch(() => {
|
||||
this.isLoadingFields = false;
|
||||
this.isLoadingMetadata = false;
|
||||
});
|
||||
},
|
||||
mounted() {
|
||||
|
@ -378,7 +378,7 @@ export default {
|
|||
width: 1em;
|
||||
}
|
||||
|
||||
.active-fields-area {
|
||||
.active-metadata-area {
|
||||
font-size: 14px;
|
||||
margin-right: 0.8em;
|
||||
margin-left: -0.8em;
|
||||
|
@ -394,7 +394,7 @@ export default {
|
|||
padding-right: 1em;
|
||||
}
|
||||
|
||||
&.fields-area-receive {
|
||||
&.metadata-area-receive {
|
||||
border: 1px dashed gray;
|
||||
}
|
||||
|
||||
|
@ -402,7 +402,7 @@ export default {
|
|||
display: initial;
|
||||
}
|
||||
|
||||
.active-field-item {
|
||||
.active-metadatum-item {
|
||||
background-color: white;
|
||||
padding: 0.7em 0.9em;
|
||||
margin: 4px;
|
||||
|
@ -420,7 +420,7 @@ export default {
|
|||
top: 2px;
|
||||
position: relative;
|
||||
}
|
||||
.field-name {
|
||||
.metadatum-name {
|
||||
text-overflow: ellipsis;
|
||||
overflow-x: hidden;
|
||||
white-space: nowrap;
|
||||
|
@ -467,18 +467,18 @@ export default {
|
|||
&.not-focusable-item, &.not-focusable-item:hover {
|
||||
cursor: default;
|
||||
|
||||
.field-name {
|
||||
.metadatum-name {
|
||||
color: $secondary;
|
||||
}
|
||||
.handle .label-details, .handle .icon {
|
||||
color: $gray !important;
|
||||
}
|
||||
}
|
||||
&.disabled-field {
|
||||
&.disabled-metadatum {
|
||||
color: $gray;
|
||||
}
|
||||
}
|
||||
.active-field-item:hover:not(.not-sortable-item) {
|
||||
.active-metadatum-item:hover:not(.not-sortable-item) {
|
||||
background-color: $secondary;
|
||||
border-color: $secondary;
|
||||
color: white !important;
|
||||
|
@ -521,7 +521,7 @@ export default {
|
|||
}
|
||||
}
|
||||
|
||||
.available-fields-area {
|
||||
.available-metadata-area {
|
||||
padding: 10px 0px 10px 10px;
|
||||
margin: 0;
|
||||
max-width: 280px;
|
||||
|
@ -533,8 +533,8 @@ export default {
|
|||
h3 {
|
||||
margin: 1em 0em 1em 0em !important;
|
||||
}
|
||||
.available-field-item::before,
|
||||
.available-field-item::after {
|
||||
.available-metadatum-item::before,
|
||||
.available-metadatum-item::after {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
|
@ -545,7 +545,7 @@ export default {
|
|||
font-weight: 500;
|
||||
}
|
||||
|
||||
.available-field-item {
|
||||
.available-metadatum-item {
|
||||
padding: 0.7em;
|
||||
margin: 4px;
|
||||
background-color: white;
|
||||
|
@ -568,7 +568,7 @@ export default {
|
|||
position: relative;
|
||||
bottom: 1px;
|
||||
}
|
||||
.field-name {
|
||||
.metadatum-name {
|
||||
text-overflow: ellipsis;
|
||||
overflow-x: hidden;
|
||||
white-space: nowrap;
|
||||
|
@ -655,7 +655,7 @@ export default {
|
|||
border-color: transparent white transparent transparent;
|
||||
}
|
||||
}
|
||||
.hightlighted-field {
|
||||
.hightlighted-metadatum {
|
||||
background-color: white;
|
||||
position: relative;
|
||||
left: 0px;
|
||||
|
@ -676,7 +676,7 @@ export default {
|
|||
animation-iteration-count: 2;
|
||||
}
|
||||
}
|
||||
.available-field-item:hover {
|
||||
.available-metadatum-item:hover {
|
||||
background-color: $secondary;
|
||||
border-color: $secondary;
|
||||
color: white;
|
|
@ -34,12 +34,12 @@
|
|||
<li>
|
||||
<router-link
|
||||
tag="a"
|
||||
to="/fields"
|
||||
:class="activeRoute == 'FieldsPage' ? 'is-active':''">
|
||||
to="/metadata"
|
||||
:class="activeRoute == 'MetadataPage' ? 'is-active':''">
|
||||
<b-icon
|
||||
size="is-small"
|
||||
icon="format-list-bulleted-type"/>
|
||||
<span class="menu-text">{{ $i18n.getFrom('fields', 'name') }}</span>
|
||||
<span class="menu-text">{{ $i18n.getFrom('metadata', 'name') }}</span>
|
||||
</router-link>
|
||||
</li>
|
||||
<li>
|
||||
|
|
|
@ -54,14 +54,14 @@
|
|||
<li class="level-item">
|
||||
<router-link
|
||||
tag="a"
|
||||
:to="{ path: $routerHelper.getCollectionFieldsPath(id) }"
|
||||
:class="activeRoute == 'FieldsList' ? 'is-active':''"
|
||||
:aria-label="$i18n.get('label_collection_fields')">
|
||||
:to="{ path: $routerHelper.getCollectionMetadataPath(id) }"
|
||||
:class="activeRoute == 'MetadataList' ? 'is-active':''"
|
||||
:aria-label="$i18n.get('label_collection_metadata')">
|
||||
<b-icon
|
||||
size="is-small"
|
||||
icon="format-list-bulleted-type"/>
|
||||
<br>
|
||||
<span class="menu-text">{{ $i18n.getFrom('fields', 'name') }}</span>
|
||||
<span class="menu-text">{{ $i18n.getFrom('metadata', 'name') }}</span>
|
||||
</router-link>
|
||||
</li>
|
||||
<li class="level-item">
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
</div>
|
||||
|
||||
<div
|
||||
v-else-if="key === 'fields_order' || key === 'filters_order'"
|
||||
v-else-if="key === 'metadata_order' || key === 'filters_order'"
|
||||
class="is-capitalized">
|
||||
{{ `ID: ${o.id} Enabled: ${o.enabled ? o.enabled : 'false'}` }}
|
||||
</div>
|
||||
|
@ -132,7 +132,7 @@
|
|||
</div>
|
||||
|
||||
<div
|
||||
v-else-if="key === 'fields_order' || key === 'filters_order'"
|
||||
v-else-if="key === 'metadata_order' || key === 'filters_order'"
|
||||
class="is-capitalized"
|
||||
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }">
|
||||
{{ `ID: ${d.id} Enabled: ${d.enabled ? d.enabled : 'false'}` }}
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
</div>
|
||||
|
||||
<div
|
||||
v-else-if="key === 'fields_order' || key === 'filters_order'"
|
||||
v-else-if="key === 'metadata_order' || key === 'filters_order'"
|
||||
class="is-capitalized">
|
||||
{{ `ID: ${o.id} Enabled: ${o.enabled ? o.enabled : 'false'}` }}
|
||||
</div>
|
||||
|
@ -129,7 +129,7 @@
|
|||
</div>
|
||||
|
||||
<div
|
||||
v-else-if="key === 'fields_order' || key === 'filters_order'"
|
||||
v-else-if="key === 'metadata_order' || key === 'filters_order'"
|
||||
class="is-capitalized"
|
||||
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }">
|
||||
{{ `ID: ${d.id} Enabled: ${d.enabled ? d.enabled : 'false'}` }}
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
</div>
|
||||
|
||||
<div
|
||||
v-else-if="key === 'fields_order' || key === 'filters_order'"
|
||||
v-else-if="key === 'metadata_order' || key === 'filters_order'"
|
||||
class="is-capitalized">
|
||||
{{ `ID: ${d.id} Enabled: ${d.enabled}` }}
|
||||
</div>
|
||||
|
|
|
@ -8,17 +8,17 @@ import Buefy from 'buefy';
|
|||
import VTooltip from 'v-tooltip'
|
||||
|
||||
// Custom elements
|
||||
import Text from '../../classes/field-types/text/Text.vue';
|
||||
import Textarea from '../../classes/field-types/textarea/Textarea.vue';
|
||||
import Selectbox from '../../classes/field-types/selectbox/Selectbox.vue';
|
||||
import Numeric from '../../classes/field-types/numeric/Numeric.vue';
|
||||
import Date from '../../classes/field-types/date/Date.vue';
|
||||
import Relationship from '../../classes/field-types/relationship/Relationship.vue';
|
||||
import Category from '../../classes/field-types/category/Category.vue';
|
||||
import Text from '../../classes/metadatum-types/text/Text.vue';
|
||||
import Textarea from '../../classes/metadatum-types/textarea/Textarea.vue';
|
||||
import Selectbox from '../../classes/metadatum-types/selectbox/Selectbox.vue';
|
||||
import Numeric from '../../classes/metadatum-types/numeric/Numeric.vue';
|
||||
import Date from '../../classes/metadatum-types/date/Date.vue';
|
||||
import Relationship from '../../classes/metadatum-types/relationship/Relationship.vue';
|
||||
import Category from '../../classes/metadatum-types/category/Category.vue';
|
||||
|
||||
import FormRelationship from '../../classes/field-types/relationship/FormRelationship.vue';
|
||||
import FormCategory from '../../classes/field-types/category/FormCategory.vue';
|
||||
import FormSelectbox from '../../classes/field-types/selectbox/FormSelectbox.vue';
|
||||
import FormRelationship from '../../classes/metadatum-types/relationship/FormRelationship.vue';
|
||||
import FormCategory from '../../classes/metadatum-types/category/FormCategory.vue';
|
||||
import FormSelectbox from '../../classes/metadatum-types/selectbox/FormSelectbox.vue';
|
||||
|
||||
import FilterCustomInterval from '../../classes/filter-types/custom-interval/CustomInterval.vue';
|
||||
import FilterSelectbox from '../../classes/filter-types/selectbox/Selectbox.vue';
|
||||
|
@ -30,7 +30,7 @@ import FilterCategoryCheckbox from '../../classes/filter-types/category/Checkbox
|
|||
import FilterCategoryTaginput from '../../classes/filter-types/category/Taginput.vue';
|
||||
import FilterCategorySelectbox from '../../classes/filter-types/category/Selectbox.vue';
|
||||
|
||||
import TainacanFormItem from '../../classes/field-types/tainacan-form-item.vue';
|
||||
import TainacanFormItem from '../../classes/metadatum-types/tainacan-form-item.vue';
|
||||
import TainacanFiltersList from '../../classes/filter-types/tainacan-filter-item.vue';
|
||||
|
||||
// Remaining imports
|
||||
|
@ -54,7 +54,7 @@ Vue.use(UserCapabilitiesPlugin);
|
|||
Vue.use(ConsolePlugin, {visual: false});
|
||||
Vue.use(VueMask);
|
||||
|
||||
/* Fields */
|
||||
/* Metadata */
|
||||
Vue.component('tainacan-text', Text);
|
||||
Vue.component('tainacan-textarea', Textarea);
|
||||
Vue.component('tainacan-selectbox', Selectbox);
|
||||
|
|
|
@ -7,7 +7,7 @@ import CollectionsPage from '../pages/lists/collections-page.vue'
|
|||
import CollectionPage from '../pages/singles/collection-page.vue'
|
||||
import ItemsPage from '../pages/lists/items-page.vue'
|
||||
import ItemPage from '../pages/singles/item-page.vue'
|
||||
import FieldsPage from '../pages/lists/fields-page.vue'
|
||||
import MetadataPage from '../pages/lists/metadata-page.vue'
|
||||
import FiltersPage from '../pages/lists/filters-page.vue'
|
||||
import CategoriesPage from '../pages/lists/categories-page.vue'
|
||||
import CategoryPage from '../pages/singles/category-page.vue'
|
||||
|
@ -21,7 +21,7 @@ import CategoryEditionForm from '../components/edition/category-edition-form.vue
|
|||
|
||||
// Listing components
|
||||
import FiltersList from '../components/lists/filters-list.vue'
|
||||
import FieldsList from '../components/lists/fields-list.vue'
|
||||
import MetadataList from '../components/lists/metadata-list.vue'
|
||||
|
||||
Vue.use(VueRouter);
|
||||
|
||||
|
@ -45,7 +45,7 @@ const routes = [
|
|||
{ path: 'items/new', name: 'CollectionItemCreatePage', component: ItemEditionForm, meta: {title: i18nGet('title_create_item_collection'), icon: 'folder-multiple'} },
|
||||
{ path: 'items/:itemId', name: 'ItemPage', component: ItemPage, meta: {title: i18nGet('title_item_page'), icon: 'folder-multiple'} },
|
||||
{ path: 'settings', component: CollectionEditionForm, name: 'CollectionEditionForm', meta: {title: i18nGet('title_collection_settings'), icon: 'folder-multiple'} },
|
||||
{ path: 'fields', component: FieldsList, name: 'FieldsList', meta: {title: i18nGet('title_collection_fields_edition'), icon: 'folder-multiple'} },
|
||||
{ path: 'metadata', component: MetadataList, name: 'MetadataList', meta: {title: i18nGet('title_collection_metadata_edition'), icon: 'folder-multiple'} },
|
||||
{ path: 'filters', component: FiltersList, name: 'FiltersList', meta: {title: i18nGet('title_collection_filters_edition'), icon: 'folder-multiple'} },
|
||||
{ path: 'events', component: EventsPage, name: 'CollectionEventsPage', meta: {title: i18nGet('title_collection_events'), icon: 'flash'} }
|
||||
]
|
||||
|
@ -56,7 +56,7 @@ const routes = [
|
|||
|
||||
{ path: '/filters', name: 'FiltersPage', component: FiltersPage, meta: {title: i18nGet('title_repository_filters_page'), icon: 'filter'} },
|
||||
|
||||
{ path: '/fields', name: 'FieldsPage', component: FieldsPage, meta: {title: i18nGet('title_repository_fields_page'), icon: 'format-list-checks'} },
|
||||
{ path: '/metadata', name: 'MetadataPage', component: MetadataPage, meta: {title: i18nGet('title_repository_metadata_page'), icon: 'format-list-checks'} },
|
||||
|
||||
{ path: '/taxonomies', name: 'CategoriesPage', component: CategoriesPage, meta: {title: i18nGet('title_categories_page'), icon: 'shape'} },
|
||||
{ path: '/taxonomies/new', name: 'CategoryCreationForm', component: CategoryEditionForm, meta: {title: i18nGet('title_create_category_page'), icon: 'shape'} },
|
||||
|
|
|
@ -4,17 +4,17 @@ import Buefy from 'buefy';
|
|||
import VTooltip from 'v-tooltip'
|
||||
|
||||
// Custom elements
|
||||
import Text from '../../classes/field-types/text/Text.vue';
|
||||
import Textarea from '../../classes/field-types/textarea/Textarea.vue';
|
||||
import Selectbox from '../../classes/field-types/selectbox/Selectbox.vue';
|
||||
import Numeric from '../../classes/field-types/numeric/Numeric.vue';
|
||||
import Date from '../../classes/field-types/date/Date.vue';
|
||||
import Relationship from '../../classes/field-types/relationship/Relationship.vue';
|
||||
import Category from '../../classes/field-types/category/Category.vue';
|
||||
import Text from '../../classes/metadatum-types/text/Text.vue';
|
||||
import Textarea from '../../classes/metadatum-types/textarea/Textarea.vue';
|
||||
import Selectbox from '../../classes/metadatum-types/selectbox/Selectbox.vue';
|
||||
import Numeric from '../../classes/metadatum-types/numeric/Numeric.vue';
|
||||
import Date from '../../classes/metadatum-types/date/Date.vue';
|
||||
import Relationship from '../../classes/metadatum-types/relationship/Relationship.vue';
|
||||
import Category from '../../classes/metadatum-types/category/Category.vue';
|
||||
|
||||
import FormRelationship from '../../classes/field-types/relationship/FormRelationship.vue';
|
||||
import FormCategory from '../../classes/field-types/category/FormCategory.vue';
|
||||
import FormSelectbox from '../../classes/field-types/selectbox/FormSelectbox.vue';
|
||||
import FormRelationship from '../../classes/metadatum-types/relationship/FormRelationship.vue';
|
||||
import FormCategory from '../../classes/metadatum-types/category/FormCategory.vue';
|
||||
import FormSelectbox from '../../classes/metadatum-types/selectbox/FormSelectbox.vue';
|
||||
|
||||
import FilterCustomInterval from '../../classes/filter-types/custom-interval/CustomInterval.vue';
|
||||
import FilterSelectbox from '../../classes/filter-types/selectbox/Selectbox.vue';
|
||||
|
@ -26,7 +26,7 @@ import FilterCategoryCheckbox from '../../classes/filter-types/category/Checkbox
|
|||
import FilterCategoryTaginput from '../../classes/filter-types/category/Taginput.vue';
|
||||
import FilterCategorySelectbox from '../../classes/filter-types/category/Selectbox.vue';
|
||||
|
||||
import TaincanFormItem from '../../classes/field-types/tainacan-form-item.vue';
|
||||
import TaincanFormItem from '../../classes/metadatum-types/tainacan-form-item.vue';
|
||||
import TaincanFiltersList from '../../classes/filter-types/tainacan-filter-item.vue';
|
||||
import ItemsPage from '../pages/lists/items-page.vue';
|
||||
import TableViewMode from '../../theme-helper/table-view-mode.vue';
|
||||
|
@ -47,7 +47,7 @@ Vue.use(UserPrefsPlugin);
|
|||
Vue.use(RouterHelperPlugin);
|
||||
Vue.use(ConsolePlugin, {visual: false});
|
||||
|
||||
/* Fields */
|
||||
/* Metadata */
|
||||
Vue.component('tainacan-text', Text);
|
||||
Vue.component('tainacan-textarea', Textarea);
|
||||
Vue.component('tainacan-selectbox', Selectbox);
|
||||
|
|
|
@ -162,8 +162,8 @@ RouterHelperPlugin.install = function (Vue, options = {}) {
|
|||
getCollectionItemsPath(collectionId, query) {
|
||||
return '/collections/'+ collectionId + '/items/?' + qs.stringify(query);
|
||||
},
|
||||
getCollectionFieldsPath(collectionId) {
|
||||
return '/collections/'+ collectionId + '/fields/';
|
||||
getCollectionMetadataPath(collectionId) {
|
||||
return '/collections/'+ collectionId + '/metadata/';
|
||||
},
|
||||
getCollectionFiltersPath(collectionId) {
|
||||
return '/collections/'+ collectionId + '/filters/';
|
||||
|
@ -183,8 +183,8 @@ RouterHelperPlugin.install = function (Vue, options = {}) {
|
|||
getFiltersPath(query) {
|
||||
return '/filters/?' + qs.stringify(query);
|
||||
},
|
||||
getFieldsPath(query) {
|
||||
return '/fields/?' + qs.stringify(query);
|
||||
getMetadataPath(query) {
|
||||
return '/metadata/?' + qs.stringify(query);
|
||||
},
|
||||
getEventsPath(query) {
|
||||
return '/events/?' + qs.stringify(query);
|
||||
|
@ -218,11 +218,11 @@ RouterHelperPlugin.install = function (Vue, options = {}) {
|
|||
getNewItemPath(collectionId) {
|
||||
return '/collections/' + collectionId + '/items/new';
|
||||
},
|
||||
getNewCollectionFieldPath(collectionId) {
|
||||
return '/collections/' + collectionId + '/fields/';
|
||||
getNewCollectionMetadatumPath(collectionId) {
|
||||
return '/collections/' + collectionId + '/metadata/';
|
||||
},
|
||||
getNewFieldPath() {
|
||||
return '/fields';
|
||||
getNewMetadatumPath() {
|
||||
return '/metadata';
|
||||
},
|
||||
getNewCollectionFilterPath(collectionId) {
|
||||
return '/collections/' + collectionId + '/filters/';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<div class="primary-page page-container">
|
||||
<b-loading :active.sync="isLoadingFieldMappers"/>
|
||||
<b-loading :active.sync="isLoadingMetadatumMappers"/>
|
||||
<tainacan-title />
|
||||
<div
|
||||
class="sub-header"
|
||||
|
@ -24,14 +24,14 @@
|
|||
</router-link>
|
||||
</b-dropdown-item>
|
||||
<b-dropdown-item
|
||||
:key="field_mapper.slug"
|
||||
v-for="field_mapper in field_mappers"
|
||||
v-if="field_mapper.metadata != false">
|
||||
:key="metadatum_mapper.slug"
|
||||
v-for="metadatum_mapper in metadatum_mappers"
|
||||
v-if="metadatum_mapper.metadata != false">
|
||||
<router-link
|
||||
:id="'a-create-collection-' + field_mapper.slug"
|
||||
:id="'a-create-collection-' + metadatum_mapper.slug"
|
||||
tag="div"
|
||||
:to="{ path: $routerHelper.getNewMappedCollectionPath(field_mapper.slug) }">
|
||||
{{ $i18n.get(field_mapper.name) }}
|
||||
:to="{ path: $routerHelper.getNewMappedCollectionPath(metadatum_mapper.slug) }">
|
||||
{{ $i18n.get(metadatum_mapper.name) }}
|
||||
</router-link>
|
||||
</b-dropdown-item>
|
||||
</b-dropdown>
|
||||
|
@ -140,7 +140,7 @@ export default {
|
|||
totalCollections: 0,
|
||||
page: 1,
|
||||
collectionsPerPage: 12,
|
||||
isLoadingFieldMappers: true,
|
||||
isLoadingMetadatumMappers: true,
|
||||
status: ''
|
||||
}
|
||||
},
|
||||
|
@ -151,14 +151,14 @@ export default {
|
|||
...mapActions('collection', [
|
||||
'fetchCollections',
|
||||
]),
|
||||
...mapActions('fields', [
|
||||
'fetchFieldMappers'
|
||||
...mapActions('metadata', [
|
||||
'fetchMetadatumMappers'
|
||||
]),
|
||||
...mapGetters('collection', [
|
||||
'getCollections'
|
||||
]),
|
||||
...mapGetters('fields', [
|
||||
'getFieldMappers'
|
||||
...mapGetters('metadata', [
|
||||
'getMetadatumMappers'
|
||||
]),
|
||||
onChangeTab(status) {
|
||||
this.status = status;
|
||||
|
@ -192,9 +192,9 @@ export default {
|
|||
}
|
||||
},
|
||||
computed: {
|
||||
field_mappers: {
|
||||
metadatum_mappers: {
|
||||
get() {
|
||||
return this.getFieldMappers();
|
||||
return this.getMetadatumMappers();
|
||||
}
|
||||
},
|
||||
collections() {
|
||||
|
@ -202,7 +202,7 @@ export default {
|
|||
}
|
||||
},
|
||||
created() {
|
||||
this.isLoadingFieldTypes = true;
|
||||
this.isLoadingMetadatumTypes = true;
|
||||
this.$userPrefs.get('collections_per_page')
|
||||
.then((value) => {
|
||||
this.collectionsPerPage = value;
|
||||
|
@ -210,12 +210,12 @@ export default {
|
|||
.catch(() => {
|
||||
this.$userPrefs.set('collections_per_page', 12, null);
|
||||
});
|
||||
this.fetchFieldMappers()
|
||||
this.fetchMetadatumMappers()
|
||||
.then(() => {
|
||||
this.isLoadingFieldMappers = false;
|
||||
this.isLoadingMetadatumMappers = false;
|
||||
})
|
||||
.catch(() => {
|
||||
this.isLoadingFieldMappers = false;
|
||||
this.isLoadingMetadatumMappers = false;
|
||||
});
|
||||
},
|
||||
mounted(){
|
||||
|
|
|
@ -104,7 +104,7 @@
|
|||
class="search-control">
|
||||
<b-loading
|
||||
:is-full-page="false"
|
||||
:active.sync="isLoadingFields"/>
|
||||
:active.sync="isLoadingMetadata"/>
|
||||
<!-- Item Creation Dropdown, only on Admin -->
|
||||
<div
|
||||
class="search-control-item"
|
||||
|
@ -136,12 +136,12 @@
|
|||
</b-dropdown>
|
||||
|
||||
</div>
|
||||
<!-- Displayed Fields Dropdown -->
|
||||
<!-- Displayed Metadata Dropdown -->
|
||||
<div
|
||||
v-if="!isOnTheme || registeredViewModes[viewMode].dynamic_metadata"
|
||||
class="search-control-item">
|
||||
<b-dropdown
|
||||
ref="displayedFieldsDropdown"
|
||||
ref="displayedMetadataDropdown"
|
||||
:mobile-modal="false"
|
||||
:disabled="totalItems <= 0 || adminViewMode == 'grid'"
|
||||
class="show">
|
||||
|
@ -153,7 +153,7 @@
|
|||
</button>
|
||||
<div class="metadata-options-container">
|
||||
<b-dropdown-item
|
||||
v-for="(column, index) in localTableFields"
|
||||
v-for="(column, index) in localTableMetadata"
|
||||
:key="index"
|
||||
class="control"
|
||||
custom>
|
||||
|
@ -166,7 +166,7 @@
|
|||
</div>
|
||||
<div class="dropdown-item-apply">
|
||||
<button
|
||||
@click="onChangeDisplayedFields()"
|
||||
@click="onChangeDisplayedMetadata()"
|
||||
class="button is-success">
|
||||
{{ $i18n.get('label_apply_changes') }}
|
||||
</button>
|
||||
|
@ -182,19 +182,20 @@
|
|||
@input="onChangeOrderBy($event)"
|
||||
:placeholder="$i18n.get('label_sorting')">
|
||||
<option
|
||||
v-for="field in tableFields"
|
||||
v-for="metadatum in tableMetadata"
|
||||
v-if="
|
||||
field.id === 'creation_date' ||
|
||||
field.id === 'author_name' || (
|
||||
field.id !== undefined &&
|
||||
field.field_type_object.related_mapped_prop !== 'description' &&
|
||||
field.field_type_object.primitive_type !== 'term' &&
|
||||
field.field_type_object.primitive_type !== 'item' &&
|
||||
field.field_type_object.primitive_type !== 'compound'
|
||||
metadatum.id === 'creation_date' ||
|
||||
metadatum.id === 'author_name' || (
|
||||
metadatum.id !== undefined &&
|
||||
metadatum.metadatum_type_object &&
|
||||
metadatum.metadatum_type_object.related_mapped_prop !== 'description' &&
|
||||
metadatum.metadatum_type_object.primitive_type !== 'term' &&
|
||||
metadatum.metadatum_type_object.primitive_type !== 'item' &&
|
||||
metadatum.metadatum_type_object.primitive_type !== 'compound'
|
||||
)"
|
||||
:value="field"
|
||||
:key="field.id">
|
||||
{{ field.name }}
|
||||
:value="metadatum"
|
||||
:key="metadatum.id">
|
||||
{{ metadatum.name }}
|
||||
</option>
|
||||
</b-select>
|
||||
<button
|
||||
|
@ -291,7 +292,7 @@
|
|||
</div>
|
||||
<advanced-search
|
||||
:is-repository-level="isRepositoryLevel"
|
||||
:metadata-list="fields" />
|
||||
:metadata-list="metadata" />
|
||||
</div>
|
||||
|
||||
|
||||
|
@ -336,7 +337,7 @@
|
|||
advancedSearchResults"
|
||||
|
||||
:collection-id="collectionId"
|
||||
:table-fields="tableFields"
|
||||
:table-metadata="tableMetadata"
|
||||
:items="items"
|
||||
:is-loading="isLoadingItems"
|
||||
:is-on-trash="status == 'trash'"
|
||||
|
@ -350,7 +351,7 @@
|
|||
!openAdvancedSearch"
|
||||
|
||||
:collection-id="collectionId"
|
||||
:table-fields="tableFields"
|
||||
:table-metadata="tableMetadata"
|
||||
:items="items"
|
||||
:is-loading="isLoadingItems"
|
||||
:is-on-trash="status == 'trash'"
|
||||
|
@ -369,7 +370,7 @@
|
|||
registeredViewModes[viewMode] != undefined &&
|
||||
registeredViewModes[viewMode].type == 'component'"
|
||||
:collection-id="collectionId"
|
||||
:table-fields="tableFields"
|
||||
:table-metadata="tableMetadata"
|
||||
:items="items"
|
||||
:is-loading="isLoadingItems"
|
||||
:is="'table-view-mode'"/>
|
||||
|
@ -430,18 +431,18 @@
|
|||
data() {
|
||||
return {
|
||||
isRepositoryLevel: false,
|
||||
tableFields: [],
|
||||
prefTableFields: [],
|
||||
tableMetadata: [],
|
||||
prefTableMetadata: [],
|
||||
isLoadingItems: false,
|
||||
isLoadingFilters: false,
|
||||
isLoadingFields: false,
|
||||
isLoadingMetadata: false,
|
||||
hasFiltered: false,
|
||||
isFiltersMenuCompressed: false,
|
||||
collapseAll: true,
|
||||
isOnTheme: false,
|
||||
futureSearchQuery: '',
|
||||
isHeaderShrinked: false,
|
||||
localTableFields: [],
|
||||
localTableMetadata: [],
|
||||
registeredViewModes: tainacan_plugin.registered_view_modes,
|
||||
adminViewMode: 'table',
|
||||
openAdvancedSearch: false,
|
||||
|
@ -466,8 +467,8 @@
|
|||
filters() {
|
||||
return this.getFilters();
|
||||
},
|
||||
fields() {
|
||||
return this.getFields();
|
||||
metadata() {
|
||||
return this.getMetadata();
|
||||
},
|
||||
searchQuery() {
|
||||
return this.getSearchQuery();
|
||||
|
@ -492,8 +493,8 @@
|
|||
AdvancedSearch,
|
||||
},
|
||||
watch: {
|
||||
tableFields() {
|
||||
this.localTableFields = JSON.parse(JSON.stringify(this.tableFields));
|
||||
tableMetadata() {
|
||||
this.localTableMetadata = JSON.parse(JSON.stringify(this.tableMetadata));
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
@ -501,11 +502,11 @@
|
|||
'getItems',
|
||||
'getItemsListTemplate'
|
||||
]),
|
||||
...mapActions('fields', [
|
||||
'fetchFields'
|
||||
...mapActions('metadata', [
|
||||
'fetchMetadata'
|
||||
]),
|
||||
...mapGetters('fields', [
|
||||
'getFields'
|
||||
...mapGetters('metadata', [
|
||||
'getMetadata'
|
||||
]),
|
||||
...mapActions('filter', [
|
||||
'fetchFilters'
|
||||
|
@ -524,8 +525,8 @@
|
|||
updateSearch() {
|
||||
this.$eventBusSearch.setSearchQuery(this.futureSearchQuery);
|
||||
},
|
||||
onChangeOrderBy(field) {
|
||||
this.$eventBusSearch.setOrderBy(field);
|
||||
onChangeOrderBy(metadatum) {
|
||||
this.$eventBusSearch.setOrderBy(metadatum);
|
||||
},
|
||||
onChangeOrder() {
|
||||
this.order == 'DESC' ? this.$eventBusSearch.setOrder('ASC') : this.$eventBusSearch.setOrder('DESC');
|
||||
|
@ -536,31 +537,31 @@
|
|||
onChangeViewMode(viewMode) {
|
||||
this.$eventBusSearch.setViewMode(viewMode);
|
||||
},
|
||||
onChangeDisplayedFields() {
|
||||
let fetchOnlyFieldIds = [];
|
||||
onChangeDisplayedMetadata() {
|
||||
let fetchOnlyMetadatumIds = [];
|
||||
|
||||
for (let i = 0; i < this.localTableFields.length; i++) {
|
||||
for (let i = 0; i < this.localTableMetadata.length; i++) {
|
||||
|
||||
this.tableFields[i].display = this.localTableFields[i].display;
|
||||
if (this.tableFields[i].id != undefined) {
|
||||
if (this.tableFields[i].display) {
|
||||
fetchOnlyFieldIds.push(this.tableFields[i].id);
|
||||
this.tableMetadata[i].display = this.localTableMetadata[i].display;
|
||||
if (this.tableMetadata[i].id != undefined) {
|
||||
if (this.tableMetadata[i].display) {
|
||||
fetchOnlyMetadatumIds.push(this.tableMetadata[i].id);
|
||||
}
|
||||
}
|
||||
}
|
||||
let thumbnailField = this.localTableFields.find(field => field.slug == 'thumbnail');
|
||||
let creationDateField = this.localTableFields.find(field => field.slug == 'creation_date');
|
||||
let authorNameField = this.localTableFields.find(field => field.slug == 'author_name');
|
||||
let thumbnailMetadatum = this.localTableMetadata.find(metadatum => metadatum.slug == 'thumbnail');
|
||||
let creationDateMetadatum = this.localTableMetadata.find(metadatum => metadatum.slug == 'creation_date');
|
||||
let authorNameMetadatum = this.localTableMetadata.find(metadatum => metadatum.slug == 'author_name');
|
||||
|
||||
this.$eventBusSearch.addFetchOnly({
|
||||
'0': thumbnailField.display ? 'thumbnail' : null,
|
||||
'meta': fetchOnlyFieldIds,
|
||||
'1': creationDateField.display ? 'creation_date' : null,
|
||||
'2': authorNameField.display ? 'author_name': null
|
||||
'0': thumbnailMetadatum.display ? 'thumbnail' : null,
|
||||
'meta': fetchOnlyMetadatumIds,
|
||||
'1': creationDateMetadatum.display ? 'creation_date' : null,
|
||||
'2': authorNameMetadatum.display ? 'author_name': null
|
||||
});
|
||||
this.$refs.displayedFieldsDropdown.toggle();
|
||||
this.$refs.displayedMetadataDropdown.toggle();
|
||||
},
|
||||
prepareFieldsAndFilters() {
|
||||
prepareMetadataAndFilters() {
|
||||
|
||||
this.isLoadingFilters = true;
|
||||
|
||||
|
@ -573,89 +574,89 @@
|
|||
.then(() => this.isLoadingFilters = false)
|
||||
.catch(() => this.isLoadingFilters = false);
|
||||
|
||||
this.isLoadingFields = true;
|
||||
this.isLoadingMetadata = true;
|
||||
// Processing is done inside a local variable
|
||||
let fields = [];
|
||||
this.fetchFields({
|
||||
let metadata = [];
|
||||
this.fetchMetadata({
|
||||
collectionId: this.collectionId,
|
||||
isRepositoryLevel: this.isRepositoryLevel,
|
||||
isContextEdit: !this.isOnTheme
|
||||
})
|
||||
.then(() => {
|
||||
|
||||
fields.push({
|
||||
metadata.push({
|
||||
name: this.$i18n.get('label_thumbnail'),
|
||||
field: 'row_thumbnail',
|
||||
field_type: undefined,
|
||||
metadatum: 'row_thumbnail',
|
||||
metadatum_type: undefined,
|
||||
slug: 'thumbnail',
|
||||
id: undefined,
|
||||
display: true
|
||||
});
|
||||
|
||||
let fetchOnlyFieldIds = [];
|
||||
let fetchOnlyMetadatumIds = [];
|
||||
|
||||
for (let field of this.fields) {
|
||||
if (field.display !== 'never') {
|
||||
for (let metadatum of this.metadata) {
|
||||
if (metadatum.display !== 'never') {
|
||||
|
||||
let display;
|
||||
|
||||
if (field.display == 'no')
|
||||
if (metadatum.display == 'no')
|
||||
display = false;
|
||||
else if (field.display == 'yes')
|
||||
else if (metadatum.display == 'yes')
|
||||
display = true;
|
||||
|
||||
fields.push(
|
||||
metadata.push(
|
||||
{
|
||||
name: field.name,
|
||||
field: field.description,
|
||||
slug: field.slug,
|
||||
field_type: field.field_type,
|
||||
field_type_object: field.field_type_object,
|
||||
id: field.id,
|
||||
name: metadatum.name,
|
||||
metadatum: metadatum.description,
|
||||
slug: metadatum.slug,
|
||||
metadatum_type: metadatum.metadatum_type,
|
||||
metadatum_type_object: metadatum.metadatum_type_object,
|
||||
id: metadatum.id,
|
||||
display: display
|
||||
}
|
||||
);
|
||||
if (display)
|
||||
fetchOnlyFieldIds.push(field.id);
|
||||
fetchOnlyMetadatumIds.push(metadatum.id);
|
||||
}
|
||||
}
|
||||
|
||||
fields.push({
|
||||
metadata.push({
|
||||
name: this.$i18n.get('label_creation_date'),
|
||||
field: 'row_creation',
|
||||
field_type: undefined,
|
||||
metadatum: 'row_creation',
|
||||
metadatum_type: undefined,
|
||||
slug: 'creation_date',
|
||||
id: undefined,
|
||||
display: true
|
||||
});
|
||||
fields.push({
|
||||
metadata.push({
|
||||
name: this.$i18n.get('label_created_by'),
|
||||
field: 'row_author',
|
||||
field_type: undefined,
|
||||
metadatum: 'row_author',
|
||||
metadatum_type: undefined,
|
||||
slug: 'author_name',
|
||||
id: undefined,
|
||||
display: true
|
||||
});
|
||||
|
||||
// this.prefTableFields = this.tableFields;
|
||||
// this.prefTableMetadata = this.tableMetadata;
|
||||
// this.$userPrefs.get('table_columns_' + this.collectionId)
|
||||
// .then((value) => {
|
||||
// this.prefTableFields = value;
|
||||
// this.prefTableMetadata = value;
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// this.$userPrefs.set('table_columns_' + this.collectionId, this.prefTableFields, null);
|
||||
// this.$userPrefs.set('table_columns_' + this.collectionId, this.prefTableMetadata, null);
|
||||
// });
|
||||
this.$eventBusSearch.addFetchOnly({
|
||||
'0': 'thumbnail',
|
||||
'meta': fetchOnlyFieldIds,
|
||||
'meta': fetchOnlyMetadatumIds,
|
||||
'1': 'creation_date',
|
||||
'2': 'author_name'
|
||||
});
|
||||
this.isLoadingFields = false;
|
||||
this.tableFields = fields;
|
||||
this.isLoadingMetadata = false;
|
||||
this.tableMetadata = metadata;
|
||||
})
|
||||
.catch(() => {
|
||||
this.isLoadingFields = false;
|
||||
this.isLoadingMetadata = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
@ -675,12 +676,12 @@
|
|||
this.hasFiltered = hasFiltered;
|
||||
});
|
||||
|
||||
this.$eventBusSearch.$on('hasToPrepareFieldsAndFilters', (to) => {
|
||||
/* This condition is to prevent a incorrect fetch by filter or fields when we come from items
|
||||
this.$eventBusSearch.$on('hasToPrepareMetadataAndFilters', (to) => {
|
||||
/* This condition is to prevent a incorrect fetch by filter or metadata when we come from items
|
||||
* at collection level to items page at repository level
|
||||
*/
|
||||
if (this.collectionId === to.params.collectionId) {
|
||||
this.prepareFieldsAndFilters();
|
||||
this.prepareMetadataAndFilters();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -692,8 +693,8 @@
|
|||
},
|
||||
mounted() {
|
||||
|
||||
this.prepareFieldsAndFilters();
|
||||
this.localTableFields = JSON.parse(JSON.stringify(this.tableFields));
|
||||
this.prepareMetadataAndFilters();
|
||||
this.localTableMetadata = JSON.parse(JSON.stringify(this.tableMetadata));
|
||||
|
||||
// Watch Scroll for shrinking header, only on Admin at collection level
|
||||
if (!this.isRepositoryLevel && !this.isOnTheme) {
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
<template>
|
||||
<div class="primary-page page-container">
|
||||
<tainacan-title />
|
||||
<fields-list/>
|
||||
<metadata-list/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import FieldsList from '../../components/lists/fields-list.vue';
|
||||
import MetadataList from '../../components/lists/metadata-list.vue';
|
||||
|
||||
export default {
|
||||
name: 'FieldsPage',
|
||||
name: 'MetadataPage',
|
||||
data(){
|
||||
return {
|
||||
}
|
||||
},
|
||||
components: {
|
||||
FieldsList
|
||||
MetadataList
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -89,7 +89,7 @@
|
|||
<div
|
||||
v-show="!isMetadataColumnCompressed"
|
||||
class="column is-4-5">
|
||||
<label class="section-label">{{ $i18n.get('fields') }}</label>
|
||||
<label class="section-label">{{ $i18n.get('metadata') }}</label>
|
||||
<br>
|
||||
<a
|
||||
class="collapse-all"
|
||||
|
@ -100,10 +100,10 @@
|
|||
:icon=" open ? 'menu-down' : 'menu-right'"/>
|
||||
</a>
|
||||
|
||||
<!-- Fields -------------------------------- -->
|
||||
<!-- Metadata -------------------------------- -->
|
||||
<div>
|
||||
<div
|
||||
v-for="(field, index) of fieldList"
|
||||
v-for="(metadatum, index) of metadatumList"
|
||||
:key="index"
|
||||
class="field">
|
||||
<b-collapse :open="open">
|
||||
|
@ -115,17 +115,17 @@
|
|||
type="is-secondary"
|
||||
:icon="props.open ? 'menu-down' : 'menu-right'"
|
||||
/>
|
||||
{{ field.field.name }}
|
||||
{{ metadatum.metadatum.name }}
|
||||
</label>
|
||||
<div
|
||||
v-if="field.date_i18n"
|
||||
v-if="metadatum.date_i18n"
|
||||
class="content">
|
||||
<p v-html="field.date_i18n"/>
|
||||
<p v-html="metadatum.date_i18n"/>
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
class="content">
|
||||
<p v-html="field.value_as_html"/>
|
||||
<p v-html="metadatum.value_as_html"/>
|
||||
</div>
|
||||
</b-collapse>
|
||||
</div>
|
||||
|
@ -157,16 +157,16 @@
|
|||
...mapActions('item', [
|
||||
'fetchItem',
|
||||
'fetchAttachments',
|
||||
'fetchFields',
|
||||
'fetchMetadata',
|
||||
]),
|
||||
...mapGetters('item', [
|
||||
'getItem',
|
||||
'getFields',
|
||||
'getMetadata',
|
||||
'getAttachments'
|
||||
]),
|
||||
loadMetadata() {
|
||||
// Obtains Item Field
|
||||
this.fetchFields(this.itemId).then(() => {
|
||||
// Obtains Item Metadatum
|
||||
this.fetchMetadata(this.itemId).then(() => {
|
||||
this.isLoading = false;
|
||||
});
|
||||
},
|
||||
|
@ -175,8 +175,8 @@
|
|||
item() {
|
||||
return this.getItem();
|
||||
},
|
||||
fieldList() {
|
||||
return JSON.parse(JSON.stringify(this.getFields()));
|
||||
metadatumList() {
|
||||
return JSON.parse(JSON.stringify(this.getMetadata()));
|
||||
},
|
||||
attachmentsList() {
|
||||
return this.getAttachments();
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
display: inline-block;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.required-field-asterisk {
|
||||
.required-metadatum-asterisk {
|
||||
color: $gray;
|
||||
&.is-danger {
|
||||
color: $danger;
|
||||
|
|
|
@ -12,13 +12,13 @@ return apply_filters('tainacan-admin-i18n',[
|
|||
'repository' => __( 'Repository', 'tainacan' ),
|
||||
'collections' => __( 'Collections', 'tainacan' ),
|
||||
'items' => __( 'Items', 'tainacan' ),
|
||||
'fields' => __( 'Metadata', 'tainacan' ),
|
||||
'metadata' => __( 'Metadata', 'tainacan' ),
|
||||
'filters' => __( 'Filters', 'tainacan' ),
|
||||
'taxonomies' => __( 'Taxonomies', 'tainacan' ),
|
||||
'events' => __( 'Events', 'tainacan' ),
|
||||
'collection' => __( 'Collection', 'tainacan' ),
|
||||
'item' => __( 'Item', 'tainacan' ),
|
||||
'field' => __( 'Metadata', 'tainacan' ),
|
||||
'metadatum' => __( 'Metadata', 'tainacan' ),
|
||||
'filter' => __( 'Filter', 'tainacan' ),
|
||||
'taxonomy' => __( 'Taxonomia', 'tainacan' ),
|
||||
'event' => __( 'Event', 'tainacan' ),
|
||||
|
@ -51,7 +51,7 @@ return apply_filters('tainacan-admin-i18n',[
|
|||
'new_blank_collection' => __( 'New Blank Collection', 'tainacan' ),
|
||||
'split' => __( 'Split', 'tainacan' ),
|
||||
'unified' => __( 'Unified', 'tainacan' ),
|
||||
'add_more_one_search_field' => __( 'Add more one search field', 'tainacan' ),
|
||||
'add_more_one_search_metadatum' => __( 'Add more one search metadatum', 'tainacan' ),
|
||||
'clear_search' => __( 'Clear search', 'tainacan' ),
|
||||
|
||||
// Wordpress Status
|
||||
|
@ -66,14 +66,14 @@ return apply_filters('tainacan-admin-i18n',[
|
|||
// Page Titles (used mainly on Router)
|
||||
'title_repository_collections_page' => __( 'Repository Collections', 'tainacan' ),
|
||||
'title_items_page' => __( 'Items', 'tainacan' ),
|
||||
'title_repository_fields_page' => __( 'Repository Metadata', 'tainacan' ),
|
||||
'title_repository_metadata_page' => __( 'Repository Metadata', 'tainacan' ),
|
||||
'title_repository_filters_page' => __( 'Repository Filters', 'tainacan' ),
|
||||
'title_categories_page' => __( 'Categories Page', 'tainacan' ),
|
||||
'title_terms_page' => __( 'Terms', 'tainacan' ),
|
||||
'title_repository_events_page' => __( 'Repository Events', 'tainacan' ),
|
||||
'title_collection_page' => __( 'Collection', 'tainacan' ),
|
||||
'title_item_page' => __( 'Item', 'tainacan' ),
|
||||
'title_field_page' => __( 'Metadata', 'tainacan' ),
|
||||
'title_metadatum_page' => __( 'Metadata', 'tainacan' ),
|
||||
'title_collection_events' => __( 'Collection Events', 'tainacan' ),
|
||||
'title_filter_page' => __( 'Filter', 'tainacan' ),
|
||||
'title_category_page' => __( 'Taxonomy', 'tainacan' ),
|
||||
|
@ -87,8 +87,8 @@ return apply_filters('tainacan-admin-i18n',[
|
|||
'title_edit_item' => __( 'Edit Item', 'tainacan' ),
|
||||
'title_category_edition_page' => __( 'Taxonomy Edition', 'tainacan' ),
|
||||
'title_filter_edition' => __( 'Filter Edition', 'tainacan' ),
|
||||
'title_field_edition' => __( 'Metadata Edition', 'tainacan' ),
|
||||
'title_collection_fields_edition' => __( 'Edit Metadata of', 'tainacan' ),
|
||||
'title_metadatum_edition' => __( 'Metadata Edition', 'tainacan' ),
|
||||
'title_collection_metadata_edition' => __( 'Edit Metadata of', 'tainacan' ),
|
||||
'title_collection_filters_edition' => __( 'Edit Filters of', 'tainacan' ),
|
||||
|
||||
// Labels (used mainly on Aria Labels and Inputs)
|
||||
|
@ -124,9 +124,9 @@ return apply_filters('tainacan-admin-i18n',[
|
|||
'label_categories_per_page' => __( 'Categories per Page:', 'tainacan' ),
|
||||
'label_events_per_page' => __( 'Events per Page:', 'tainacan' ),
|
||||
'label_items_per_page' => __( 'Items per Page:', 'tainacan' ),
|
||||
'label_active_fields' => __( 'Active Metadata', 'tainacan' ),
|
||||
'label_available_fields' => __( 'Available Metadata', 'tainacan' ),
|
||||
'label_available_field_types' => __( 'Available Metadata Types', 'tainacan' ),
|
||||
'label_active_metadata' => __( 'Active Metadata', 'tainacan' ),
|
||||
'label_available_metadata' => __( 'Available Metadata', 'tainacan' ),
|
||||
'label_available_metadatum_types' => __( 'Available Metadata Types', 'tainacan' ),
|
||||
'label_active_filters' => __( 'Active Filters', 'tainacan' ),
|
||||
'label_filter_type' => __( 'Filter Type', 'tainacan' ),
|
||||
'label_available_filters' => __( 'Available Filters', 'tainacan' ),
|
||||
|
@ -141,7 +141,7 @@ return apply_filters('tainacan-admin-i18n',[
|
|||
'label_no' => __( 'No', 'tainacan' ),
|
||||
'label_approved' => __( 'Approved', 'tainacan' ),
|
||||
'label_collection_related' => __( 'Collection Related', 'tainacan' ),
|
||||
'label_fields_for_search' => __( 'Metadata for search', 'tainacan' ),
|
||||
'label_metadata_for_search' => __( 'Metadata for search', 'tainacan' ),
|
||||
'label_allow_repeated_items' => __( 'Allow repeated items', 'tainacan' ),
|
||||
'label_select_category' => __( 'Select taxonomy', 'tainacan' ),
|
||||
'label_select_category_input_type' => __( 'Input type', 'tainacan' ),
|
||||
|
@ -155,7 +155,7 @@ return apply_filters('tainacan-admin-i18n',[
|
|||
'label_creation' => __( 'Creation', 'tainacan' ),
|
||||
'label_creation_date' => __( 'Creation date', 'tainacan' ),
|
||||
'label_collection_items' => __( 'Collection Items', 'tainacan' ),
|
||||
'label_collection_fields' => __( 'Collection Metadata', 'tainacan' ),
|
||||
'label_collection_metadata' => __( 'Collection Metadata', 'tainacan' ),
|
||||
'label_collection_filters' => __( 'Collection Filters', 'tainacan' ),
|
||||
'label_parent_term' => __( 'Parent Term', 'tainacan' ),
|
||||
'label_new_term' => __( 'New Term', 'tainacan' ),
|
||||
|
@ -171,7 +171,7 @@ return apply_filters('tainacan-admin-i18n',[
|
|||
'label_empty_header_image' => __( 'Empty Header Image', 'tainacan' ),
|
||||
'label_enable_cover_page' => __( 'Enable Cover Page', 'tainacan' ),
|
||||
'label_cover_page' => __( 'Cover Page', 'tainacan' ),
|
||||
'label_default_displayed_fields' => __( 'Default Displayed Metadata', 'tainacan' ),
|
||||
'label_default_displayed_metadata' => __( 'Default Displayed Metadata', 'tainacan' ),
|
||||
'label_display' => __( 'Display on Listing', 'tainacan' ),
|
||||
'label_display_default' => __( 'Display by default', 'tainacan' ),
|
||||
'label_display_never' => __( 'Never displayed', 'tainacan' ),
|
||||
|
@ -270,7 +270,7 @@ return apply_filters('tainacan-admin-i18n',[
|
|||
'info_warning_selected_items_trash' => __( 'Do you really want to trash the selected items?', 'tainacan' ),
|
||||
'info_warning_selected_categories_delete' => __( 'Do you really want to delete the selected categories?', 'tainacan' ),
|
||||
'info_warning_collection_related' => __( 'The metadata Collection related is required', 'tainacan' ),
|
||||
'info_warning_no_fields_found' => __( 'No metadata found in this collection', 'tainacan' ),
|
||||
'info_warning_no_metadata_found' => __( 'No metadata found in this collection', 'tainacan' ),
|
||||
'info_showing_items' => __( 'Showing items ', 'tainacan' ),
|
||||
'info_showing_collections' => __( 'Showing collections ', 'tainacan' ),
|
||||
'info_showing_categories' => __( 'Showing categories ', 'tainacan' ),
|
||||
|
@ -282,7 +282,7 @@ return apply_filters('tainacan-admin-i18n',[
|
|||
'info_date' => __( 'Date: ', 'tainacan' ),
|
||||
'info_not_saved' => __( 'Not saved ', 'tainacan' ),
|
||||
'info_warning_item_not_saved' => __( 'Are you sure? The item is not saved, changes will be lost.', 'tainacan' ),
|
||||
'info_warning_fields_not_saved' => __( 'Are you sure? There are metadata not saved, changes will be lost.', 'tainacan' ),
|
||||
'info_warning_metadata_not_saved' => __( 'Are you sure? There are metadata not saved, changes will be lost.', 'tainacan' ),
|
||||
'info_warning_filters_not_saved' => __( 'Are you sure? There are filters not saved, changes will be lost.', 'tainacan' ),
|
||||
'info_no_description_provided' => __( 'No description provided.', 'tainacan' ),
|
||||
'info_warning_category_not_saved' => __( 'Are you sure? The metadata is not saved, changes will be lost.', 'tainacan' ),
|
||||
|
@ -291,7 +291,7 @@ return apply_filters('tainacan-admin-i18n',[
|
|||
'info_no_events' => __( 'No events', 'tainacan' ),
|
||||
'info_logs_before' => __( 'Before updating', 'tainacan' ),
|
||||
'info_logs_after' => __( 'What was updated', 'tainacan' ),
|
||||
'info_there_is_no_field' => __( 'There is no metadata here yet.', 'tainacan' ),
|
||||
'info_there_is_no_metadatum' => __( 'There is no metadata here yet.', 'tainacan' ),
|
||||
'info_there_is_no_filter' => __( 'There is no filter here yet.', 'tainacan' ),
|
||||
'info_changes' => __( 'Changes', 'tainacan' ),
|
||||
'info_possible_external_sources' => __( 'Possible external sources: CSV, Instagram, Youtube, etc.', 'tainacan' ),
|
||||
|
@ -304,7 +304,7 @@ return apply_filters('tainacan-admin-i18n',[
|
|||
'info_create_metadata' => __( 'Click or Drag and Drop Metadata Types here for creating a new Metadata.', 'tainacan' ),
|
||||
'info_choose_your_metadata' => __( 'Choose your metadata.', 'tainacan' ),
|
||||
|
||||
// Tainacan Field Types
|
||||
// Tainacan Metadatum Types
|
||||
'tainacan-text' => __( 'Text', 'tainacan' ),
|
||||
'tainacan-textarea' => __( 'Text area', 'tainacan' ),
|
||||
'tainacan-date' => __( 'Date', 'tainacan' ),
|
||||
|
|
|
@ -90,7 +90,7 @@ class REST_Controller extends \WP_REST_Controller {
|
|||
'value' => 'value',
|
||||
'compare' => 'compare',
|
||||
'relation' => 'relation',
|
||||
'fieldtype' => 'type',
|
||||
'metadatumtype' => 'type',
|
||||
];
|
||||
|
||||
$date_query = [
|
||||
|
@ -110,7 +110,7 @@ class REST_Controller extends \WP_REST_Controller {
|
|||
|
||||
$tax_query = [
|
||||
'taxonomy' => 'taxonomy',
|
||||
'field' => 'field',
|
||||
'metadatum' => 'field',
|
||||
'terms' => 'terms',
|
||||
'operator' => 'operator',
|
||||
'relation' => 'relation',
|
||||
|
@ -140,12 +140,12 @@ class REST_Controller extends \WP_REST_Controller {
|
|||
|
||||
/**
|
||||
* @param $data
|
||||
* @param $field_name
|
||||
* @param $metadatum_name
|
||||
* @param $request
|
||||
*
|
||||
* @return \WP_Error
|
||||
*/
|
||||
function gt_user_meta( $data, $field_name, $request ) {
|
||||
function gt_user_meta( $data, $metadatum_name, $request ) {
|
||||
if( $data['id'] ){
|
||||
$user_meta = get_user_meta( $data['id'] );
|
||||
}
|
||||
|
@ -164,19 +164,19 @@ class REST_Controller extends \WP_REST_Controller {
|
|||
/**
|
||||
* @param $meta
|
||||
* @param $user
|
||||
* @param $field_name
|
||||
* @param $metadatum_name
|
||||
*
|
||||
* @param $request
|
||||
*
|
||||
* @return mixed|\WP_Error
|
||||
*/
|
||||
public function up_user_meta( $meta, $user, $field_name, $request ) {
|
||||
public function up_user_meta( $meta, $user, $metadatum_name, $request ) {
|
||||
if ( !$user->ID ) {
|
||||
return new \WP_Error( 'No user found', 'No user found', array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
$user_id = $user->ID;
|
||||
$metas = $field_name === 'meta' ? $meta : [];
|
||||
$metas = $metadatum_name === 'meta' ? $meta : [];
|
||||
|
||||
$map = [
|
||||
'metakey',
|
||||
|
@ -244,16 +244,16 @@ class REST_Controller extends \WP_REST_Controller {
|
|||
|
||||
foreach ( $request_meta_query as $index1 => $a ) {
|
||||
|
||||
// handle core field
|
||||
// handle core metadatum
|
||||
if( is_array($a) && array_key_exists("key", $a) ){
|
||||
$field = new \Tainacan\Entities\Field($a['key']);
|
||||
if( strpos( $field->get_field_type(), 'Core_Title') !== false ){
|
||||
$metadatum = new \Tainacan\Entities\Metadatum($a['key']);
|
||||
if( strpos( $metadatum->get_metadatum_type(), 'Core_Title') !== false ){
|
||||
$args[ 'post_title_in' ] = [
|
||||
'relation' => ( isset( $request_meta_query['relation']) ) ? $request_meta_query['relation'] : 'AND' ,
|
||||
'value' => ( is_array( $a['value'] ) ) ? $a['value'] : [$a['value']]
|
||||
];
|
||||
continue;
|
||||
} else if( strpos( $field->get_field_type(), 'Core_Description') !== false ) {
|
||||
} else if( strpos( $metadatum->get_metadatum_type(), 'Core_Description') !== false ) {
|
||||
$args[ 'post_content_in' ] = [
|
||||
'relation' => ( isset( $request_meta_query['relation']) ) ? $request_meta_query['relation'] : 'AND' ,
|
||||
'value' => ( is_array( $a['value'] ) ) ? $a['value'] : [$a['value']]
|
||||
|
@ -435,7 +435,7 @@ class REST_Controller extends \WP_REST_Controller {
|
|||
'description' => __('OR or AND, how the sub-arrays should be compared.'),
|
||||
'default' => 'AND',
|
||||
),
|
||||
'fieldtype' => array(
|
||||
'metadatumtype' => array(
|
||||
'type' => 'string',
|
||||
'description' => __('Custom metadata type. Possible values are NUMERIC, BINARY, CHAR, DATE, DATETIME, DECIMAL, SIGNED, TIME, UNSIGNED. Default value is CHAR. You can also specify precision and scale for the DECIMAL and NUMERIC types (for example, DECIMAL(10,5) or NUMERIC(10) are valid). The type DATE works with the compare value BETWEEN only if the date is stored at the format YYYY-MM-DD and tested with this format.'),
|
||||
),
|
||||
|
@ -507,7 +507,7 @@ class REST_Controller extends \WP_REST_Controller {
|
|||
'type' => 'string',
|
||||
'description' => __('The taxonomy data base identifier.')
|
||||
),
|
||||
'field' => array(
|
||||
'metadatum' => array(
|
||||
'type' => 'string',
|
||||
'description' => __('Select taxonomy term by. Possible values are term_id, name, slug or term_taxonomy_id. Default value is term_id.')
|
||||
),
|
||||
|
|
|
@ -11,7 +11,7 @@ class REST_Export_Controller extends REST_Controller {
|
|||
private $item_metadata_repository;
|
||||
private $items_repository;
|
||||
private $collection_repository;
|
||||
private $field_repository;
|
||||
private $metadatum_repository;
|
||||
|
||||
public function __construct() {
|
||||
$this->rest_base = 'export';
|
||||
|
@ -25,20 +25,20 @@ class REST_Export_Controller extends REST_Controller {
|
|||
* @throws \Exception
|
||||
*/
|
||||
public function init_objects() {
|
||||
$this->field_repository = Repositories\Fields::get_instance();
|
||||
$this->metadatum_repository = Repositories\Metadata::get_instance();
|
||||
$this->item_metadata_repository = Repositories\Item_Metadata::get_instance();
|
||||
$this->items_repository = Repositories\Items::get_instance();
|
||||
$this->collection_repository = Repositories\Collections::get_instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* If POST on field/collection/<collection_id>, then
|
||||
* a field will be created in matched collection and all your item will receive this field
|
||||
* If POST on metadatum/collection/<collection_id>, then
|
||||
* a metadatum will be created in matched collection and all your item will receive this metadatum
|
||||
*
|
||||
* If POST on field/item/<item_id>, then a value will be added in a field and field passed
|
||||
* If POST on metadatum/item/<item_id>, then a value will be added in a metadatum and metadatum passed
|
||||
* id body of requisition
|
||||
*
|
||||
* Both of GETs return the field of matched objects
|
||||
* Both of GETs return the metadatum of matched objects
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
|
@ -82,15 +82,15 @@ class REST_Export_Controller extends REST_Controller {
|
|||
*/
|
||||
public function get_item( $request ) {
|
||||
/*$collection_id = $request['collection_id'];
|
||||
$field_id = $request['field_id'];
|
||||
$metadatum_id = $request['metadatum_id'];
|
||||
|
||||
if($request['fetch'] === 'all_field_values'){
|
||||
$results = $this->field_repository->fetch_all_field_values($collection_id, $field_id);
|
||||
if($request['fetch'] === 'all_metadatum_values'){
|
||||
$results = $this->metadatum_repository->fetch_all_metadatum_values($collection_id, $metadatum_id);
|
||||
|
||||
return new \WP_REST_Response($results, 200);
|
||||
}
|
||||
|
||||
$result = $this->field_repository->fetch($field_id, 'OBJECT');
|
||||
$result = $this->metadatum_repository->fetch($metadatum_id, 'OBJECT');
|
||||
|
||||
$prepared_item = $this->prepare_item_for_response($result, $request);
|
||||
return new \WP_REST_Response(apply_filters('tainacan-rest-response', $prepared_item, $request), 200);*/
|
||||
|
@ -133,7 +133,7 @@ class REST_Export_Controller extends REST_Controller {
|
|||
* @return array|\WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
$items_metadata = $item->get_fields();
|
||||
$items_metadata = $item->get_metadata();
|
||||
|
||||
$prepared_item = [];
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@ class REST_Filters_Controller extends REST_Controller {
|
|||
private $collection;
|
||||
private $collection_repository;
|
||||
|
||||
private $field;
|
||||
private $field_repository;
|
||||
private $metadatum;
|
||||
private $metadatum_repository;
|
||||
|
||||
private $filter_repository;
|
||||
|
||||
|
@ -31,13 +31,13 @@ class REST_Filters_Controller extends REST_Controller {
|
|||
$this->collection = new Entities\Collection();
|
||||
$this->collection_repository = Repositories\Collections::get_instance();
|
||||
|
||||
$this->field_repository = Repositories\Fields::get_instance();
|
||||
$this->metadatum_repository = Repositories\Metadata::get_instance();
|
||||
|
||||
$this->filter_repository = Repositories\Filters::get_instance();
|
||||
}
|
||||
|
||||
public function register_routes() {
|
||||
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/field/(?P<field_id>[\d]+)/' . $this->rest_base, array(
|
||||
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/metadatum/(?P<metadatum_id>[\d]+)/' . $this->rest_base, array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::CREATABLE,
|
||||
'callback' => array($this, 'create_item'),
|
||||
|
@ -131,30 +131,30 @@ class REST_Filters_Controller extends REST_Controller {
|
|||
$filter_obj->set($attribute, $value);
|
||||
}
|
||||
|
||||
if(isset($request['collection_id']) && isset($request['field_id'])) {
|
||||
if(isset($request['collection_id']) && isset($request['metadatum_id'])) {
|
||||
$collection_id = $request['collection_id'];
|
||||
$field_id = $request['field_id'];
|
||||
$metadatum_id = $request['metadatum_id'];
|
||||
|
||||
$filter_obj->set_collection_id( $collection_id );
|
||||
$filter_obj->set_field( $field_id );
|
||||
$filter_obj->set_metadatum( $metadatum_id );
|
||||
} elseif (isset($request['collection_id'])){
|
||||
$collection_id = $request['collection_id'];
|
||||
|
||||
$filter_obj->set_collection_id( $collection_id );
|
||||
|
||||
if(!isset($body['field'])){
|
||||
throw new \InvalidArgumentException('You need provide a field id');
|
||||
if(!isset($body['metadatum'])){
|
||||
throw new \InvalidArgumentException('You need provide a metadatum id');
|
||||
}
|
||||
|
||||
$filter_obj->set_field($body['field']);
|
||||
$filter_obj->set_metadatum($body['metadatum']);
|
||||
} else {
|
||||
$filter_obj->set_collection_id( 'filter_in_repository' );
|
||||
|
||||
if(!isset($body['field'])){
|
||||
throw new \InvalidArgumentException('You need provide a field id');
|
||||
if(!isset($body['metadatum'])){
|
||||
throw new \InvalidArgumentException('You need provide a metadatum id');
|
||||
}
|
||||
|
||||
$filter_obj->set_field($body['field']);
|
||||
$filter_obj->set_metadatum($body['metadatum']);
|
||||
}
|
||||
|
||||
$filter_obj->set_filter_type($filter_type);
|
||||
|
@ -197,11 +197,11 @@ class REST_Filters_Controller extends REST_Controller {
|
|||
* @throws \Exception
|
||||
*/
|
||||
public function create_item_permissions_check( $request ) {
|
||||
if(isset($request['collection_id']) && isset($request['field_id'])) {
|
||||
$metadata = $this->field_repository->fetch( $request['field_id'] );
|
||||
if(isset($request['collection_id']) && isset($request['metadatum_id'])) {
|
||||
$metadata = $this->metadatum_repository->fetch( $request['metadatum_id'] );
|
||||
$collection = $this->collection_repository->fetch( $request['collection_id'] );
|
||||
|
||||
if ( ( $metadata instanceof Entities\Field ) && ( $collection instanceof Entities\Collection ) ) {
|
||||
if ( ( $metadata instanceof Entities\Metadatum ) && ( $collection instanceof Entities\Collection ) ) {
|
||||
return $this->filter_repository->can_edit( new Entities\Filter() ) && $metadata->can_edit() && $collection->can_edit();
|
||||
}
|
||||
|
||||
|
@ -214,7 +214,7 @@ class REST_Filters_Controller extends REST_Controller {
|
|||
|
||||
}
|
||||
|
||||
return $this->filter_repository->can_edit(new Entities\Field());
|
||||
return $this->filter_repository->can_edit(new Entities\Metadatum());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,11 +7,11 @@ use Tainacan\Entities;
|
|||
use Tainacan\Repositories;
|
||||
|
||||
class REST_Item_Metadata_Controller extends REST_Controller {
|
||||
private $field;
|
||||
private $metadatum;
|
||||
private $item_metadata_repository;
|
||||
private $item_repository;
|
||||
private $collection_repository;
|
||||
private $field_repository;
|
||||
private $metadatum_repository;
|
||||
|
||||
public function __construct() {
|
||||
$this->rest_base = 'metadata';
|
||||
|
@ -23,24 +23,24 @@ class REST_Item_Metadata_Controller extends REST_Controller {
|
|||
* Initialize objects after post_type register
|
||||
*/
|
||||
public function init_objects() {
|
||||
$this->field = new Entities\Field();
|
||||
$this->field_repository = Repositories\Fields::get_instance();
|
||||
$this->metadatum = new Entities\Metadatum();
|
||||
$this->metadatum_repository = Repositories\Metadata::get_instance();
|
||||
$this->item_metadata_repository = Repositories\Item_Metadata::get_instance();
|
||||
$this->item_repository = Repositories\Items::get_instance();
|
||||
$this->collection_repository = Repositories\Collections::get_instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* If POST on field/collection/<collection_id>, then
|
||||
* a field will be created in matched collection and all your item will receive this field
|
||||
* If POST on metadatum/collection/<collection_id>, then
|
||||
* a metadatum will be created in matched collection and all your item will receive this metadatum
|
||||
*
|
||||
* If POST on field/item/<item_id>, then a value will be added in a field and field passed
|
||||
* If POST on metadatum/item/<item_id>, then a value will be added in a metadatum and metadatum passed
|
||||
* id body of requisition
|
||||
*
|
||||
* Both of GETs return the field of matched objects
|
||||
* Both of GETs return the metadatum of matched objects
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route($this->namespace, '/item/(?P<item_id>[\d]+)/' . $this->rest_base . '/(?P<metadata_id>[\d]+)',
|
||||
register_rest_route($this->namespace, '/item/(?P<item_id>[\d]+)/' . $this->rest_base . '/(?P<metadatum_id>[\d]+)',
|
||||
array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::EDITABLE,
|
||||
|
@ -60,11 +60,11 @@ class REST_Item_Metadata_Controller extends REST_Controller {
|
|||
)
|
||||
)
|
||||
);
|
||||
register_rest_route($this->namespace, '/item/(?P<item_id>[\d]+)/'. $this->rest_base. '/(?P<metadata_id>[\d]+)',
|
||||
register_rest_route($this->namespace, '/item/(?P<item_id>[\d]+)/'. $this->rest_base. '/(?P<metadatum_id>[\d]+)',
|
||||
array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_item_field_value'),
|
||||
'callback' => array($this, 'get_item_metadatum_value'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
)
|
||||
)
|
||||
|
@ -81,12 +81,12 @@ class REST_Item_Metadata_Controller extends REST_Controller {
|
|||
|
||||
foreach ($meta as $key => $value){
|
||||
$set_ = 'set_' . $key;
|
||||
$this->field->$set_($value);
|
||||
$this->metadatum->$set_($value);
|
||||
}
|
||||
|
||||
$collection = new Entities\Collection($request[1]);
|
||||
|
||||
$this->field->set_collection($collection);
|
||||
$this->metadatum->set_collection($collection);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -115,13 +115,13 @@ class REST_Item_Metadata_Controller extends REST_Controller {
|
|||
|
||||
$item = $this->item_repository->fetch($item_id);
|
||||
|
||||
$items_metadata = $item->get_fields();
|
||||
$items_metadata = $item->get_metadata();
|
||||
|
||||
$prepared_item = [];
|
||||
|
||||
foreach ($items_metadata as $item_metadata){
|
||||
$index = array_push($prepared_item, $this->prepare_item_for_response($item_metadata, $request));
|
||||
$prepared_item[$index-1]['field']['field_type_object'] = $this->prepare_item_for_response( $item_metadata->get_field()->get_field_type_object(), $request);
|
||||
$prepared_item[$index-1]['metadatum']['metadatum_type_object'] = $this->prepare_item_for_response( $item_metadata->get_metadatum()->get_metadatum_type_object(), $request);
|
||||
}
|
||||
|
||||
return new \WP_REST_Response(apply_filters('tainacan-rest-response', $prepared_item, $request), 200);
|
||||
|
@ -132,21 +132,21 @@ class REST_Item_Metadata_Controller extends REST_Controller {
|
|||
*
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_item_field_value( $request ) {
|
||||
public function get_item_metadatum_value( $request ) {
|
||||
$item_id = $request['item_id'];
|
||||
$field_id = $request['metadata_id'];
|
||||
$metadatum_id = $request['metadatum_id'];
|
||||
|
||||
$item = $this->item_repository->fetch($item_id);
|
||||
|
||||
$items_metadata = $item->get_fields();
|
||||
$items_metadata = $item->get_metadata();
|
||||
|
||||
$prepared_item = '';
|
||||
|
||||
foreach ($items_metadata as $item_metadata){
|
||||
$field = $item_metadata->get_field();
|
||||
if($field->get_id() == $field_id) {
|
||||
$metadatum = $item_metadata->get_metadatum();
|
||||
if($metadatum->get_id() == $metadatum_id) {
|
||||
$prepared_item = $this->prepare_item_for_response($item_metadata, $request);
|
||||
$prepared_item['field']['field_type_object'] = $this->prepare_item_for_response( $field->get_field_type_object(), $request);
|
||||
$prepared_item['metadatum']['metadatum_type_object'] = $this->prepare_item_for_response( $metadatum->get_metadatum_type_object(), $request);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,13 +184,13 @@ class REST_Item_Metadata_Controller extends REST_Controller {
|
|||
if($body) {
|
||||
|
||||
$item_id = $request['item_id'];
|
||||
$field_id = $request['metadata_id'];
|
||||
$metadatum_id = $request['metadatum_id'];
|
||||
$value = $body['values'];
|
||||
|
||||
$item = $this->item_repository->fetch( $item_id );
|
||||
$field = $this->field_repository->fetch( $field_id );
|
||||
$metadatum = $this->metadatum_repository->fetch( $metadatum_id );
|
||||
|
||||
$item_metadata = new Entities\Item_Metadata_Entity( $item, $field );
|
||||
$item_metadata = new Entities\Item_Metadata_Entity( $item, $metadatum );
|
||||
|
||||
if($item_metadata->is_multiple()) {
|
||||
$item_metadata->set_value( $value );
|
||||
|
@ -202,18 +202,18 @@ class REST_Item_Metadata_Controller extends REST_Controller {
|
|||
|
||||
if ( $item_metadata->validate() ) {
|
||||
if($item->can_edit()) {
|
||||
$field_updated = $this->item_metadata_repository->update( $item_metadata );
|
||||
$metadatum_updated = $this->item_metadata_repository->update( $item_metadata );
|
||||
|
||||
$prepared_item = $this->prepare_item_for_response($field_updated, $request);
|
||||
$prepared_item['field']['field_type_object'] = $this->prepare_item_for_response($field_updated->get_field()->get_field_type_object(), $request);
|
||||
$prepared_item = $this->prepare_item_for_response($metadatum_updated, $request);
|
||||
$prepared_item['metadatum']['metadatum_type_object'] = $this->prepare_item_for_response($metadatum_updated->get_metadatum()->get_metadatum_type_object(), $request);
|
||||
}
|
||||
elseif($field->get_accept_suggestion()) {
|
||||
elseif($metadatum->get_accept_suggestion()) {
|
||||
$log = $this->item_metadata_repository->suggest( $item_metadata );
|
||||
$prepared_item = $log->_toArray();
|
||||
}
|
||||
else {
|
||||
return new \WP_REST_Response( [
|
||||
'error_message' => __( 'The metadata does not accept suggestions', 'tainacan' ),
|
||||
'error_message' => __( 'The metadatum does not accept suggestions', 'tainacan' ),
|
||||
], 400 );
|
||||
}
|
||||
|
||||
|
@ -248,9 +248,9 @@ class REST_Item_Metadata_Controller extends REST_Controller {
|
|||
return $item->can_edit();
|
||||
}
|
||||
else {
|
||||
$field_id = $request['metadata_id'];
|
||||
$field = $this->field_repository->fetch( $field_id );
|
||||
return 'publish' === $field->get_status() && $field->get_accept_suggestion();
|
||||
$metadatum_id = $request['metadatum_id'];
|
||||
$metadatum = $this->metadatum_repository->fetch( $metadatum_id );
|
||||
return 'publish' === $metadatum->get_status() && $metadatum->get_accept_suggestion();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -109,22 +109,22 @@ class REST_Items_Controller extends REST_Controller {
|
|||
* @return mixed
|
||||
*/
|
||||
private function add_metadata_to_item($item_object, $item_array, $args = []){
|
||||
$item_metadata = $item_object->get_fields($args);
|
||||
$item_metadata = $item_object->get_metadata($args);
|
||||
|
||||
foreach($item_metadata as $index => $me){
|
||||
$field = $me->get_field();
|
||||
$slug = $field->get_slug();
|
||||
$metadatum = $me->get_metadatum();
|
||||
$slug = $metadatum->get_slug();
|
||||
$item_metadata_array = $me->_toArray();
|
||||
|
||||
$item_array['metadata'][ $slug ]['name'] = $field->get_name();
|
||||
if($field->get_field_type_object()->get_primitive_type() === 'date') {
|
||||
$item_array['metadata'][ $slug ]['name'] = $metadatum->get_name();
|
||||
if($metadatum->get_metadatum_type_object()->get_primitive_type() === 'date') {
|
||||
$item_array['metadata'][ $slug ]['date_i18n'] = $item_metadata_array['date_i18n'];
|
||||
} else {
|
||||
$item_array['metadata'][ $slug ]['value'] = $item_metadata_array['value'];
|
||||
$item_array['metadata'][ $slug ]['value_as_html'] = $item_metadata_array['value_as_html'];
|
||||
$item_array['metadata'][ $slug ]['value_as_string'] = $item_metadata_array['value_as_string'];
|
||||
}
|
||||
$item_array['metadata'][ $slug ]['multiple'] = $field->get_multiple();
|
||||
$item_array['metadata'][ $slug ]['multiple'] = $metadatum->get_multiple();
|
||||
}
|
||||
|
||||
return $item_array;
|
||||
|
@ -238,11 +238,11 @@ class REST_Items_Controller extends REST_Controller {
|
|||
|
||||
ob_start();
|
||||
|
||||
global $wp_query, $view_mode_displayed_fields;
|
||||
global $wp_query, $view_mode_displayed_metadata;
|
||||
$wp_query = $items;
|
||||
$displayed_metadata = array_map(function($el) { return (int) $el; }, $request['fetch_only']['meta']);
|
||||
$view_mode_displayed_fields = $request['fetch_only'];
|
||||
$view_mode_displayed_fields['meta'] = $displayed_metadata;
|
||||
$view_mode_displayed_metadata = $request['fetch_only'];
|
||||
$view_mode_displayed_metadata['meta'] = $displayed_metadata;
|
||||
|
||||
include $view_mode['template'];
|
||||
|
||||
|
|
|
@ -6,14 +6,14 @@ use \Tainacan\API\REST_Controller;
|
|||
use Tainacan\Entities;
|
||||
use Tainacan\Repositories;
|
||||
|
||||
class REST_Fields_Controller extends REST_Controller {
|
||||
class REST_Metadata_Controller extends REST_Controller {
|
||||
private $item_metadata_repository;
|
||||
private $item_repository;
|
||||
private $collection_repository;
|
||||
private $field_repository;
|
||||
private $metadatum_repository;
|
||||
|
||||
public function __construct() {
|
||||
$this->rest_base = 'fields';
|
||||
$this->rest_base = 'metadata';
|
||||
parent::__construct();
|
||||
add_action('init', array(&$this, 'init_objects'), 11);
|
||||
}
|
||||
|
@ -24,25 +24,25 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
* @throws \Exception
|
||||
*/
|
||||
public function init_objects() {
|
||||
$this->field_repository = Repositories\Fields::get_instance();
|
||||
$this->metadatum_repository = Repositories\Metadata::get_instance();
|
||||
$this->item_metadata_repository = Repositories\Item_Metadata::get_instance();
|
||||
$this->item_repository = Repositories\Items::get_instance();
|
||||
$this->collection_repository = Repositories\Collections::get_instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* If POST on field/collection/<collection_id>, then
|
||||
* a field will be created in matched collection and all your item will receive this field
|
||||
* If POST on metadatum/collection/<collection_id>, then
|
||||
* a metadatum will be created in matched collection and all your item will receive this metadatum
|
||||
*
|
||||
* If POST on field/item/<item_id>, then a value will be added in a field and field passed
|
||||
* If POST on metadatum/item/<item_id>, then a value will be added in a metadatum and metadatum passed
|
||||
* id body of requisition
|
||||
*
|
||||
* Both of GETs return the field of matched objects
|
||||
* Both of GETs return the metadatum of matched objects
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base . '/(?P<field_id>[\d]+)',
|
||||
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base . '/(?P<metadatum_id>[\d]+)',
|
||||
array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::EDITABLE,
|
||||
|
@ -96,7 +96,7 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
)
|
||||
)
|
||||
);
|
||||
register_rest_route($this->namespace, '/'. $this->rest_base . '/(?P<field_id>[\d]+)',
|
||||
register_rest_route($this->namespace, '/'. $this->rest_base . '/(?P<metadatum_id>[\d]+)',
|
||||
array(
|
||||
// ENDPOINT Z.
|
||||
array(
|
||||
|
@ -127,28 +127,28 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
*/
|
||||
public function get_item( $request ) {
|
||||
$collection_id = isset($request['collection_id']) ? $request['collection_id'] : false;
|
||||
$field_id = $request['field_id'];
|
||||
$metadatum_id = $request['metadatum_id'];
|
||||
|
||||
if($request['fetch'] === 'all_field_values' && $request['search']){
|
||||
if($request['fetch'] === 'all_metadatum_values' && $request['search']){
|
||||
if($collection_id) {
|
||||
$results = $this->field_repository->fetch_all_field_values( $collection_id, $field_id, $request['search'] );
|
||||
$results = $this->metadatum_repository->fetch_all_metadatum_values( $collection_id, $metadatum_id, $request['search'] );
|
||||
} else {
|
||||
$results = $this->field_repository->fetch_all_field_values( null, $field_id, $request['search']);
|
||||
$results = $this->metadatum_repository->fetch_all_metadatum_values( null, $metadatum_id, $request['search']);
|
||||
}
|
||||
|
||||
return new \WP_REST_Response($results, 200);
|
||||
|
||||
} elseif($request['fetch'] === 'all_field_values') {
|
||||
} elseif($request['fetch'] === 'all_metadatum_values') {
|
||||
if($collection_id) {
|
||||
$results = $this->field_repository->fetch_all_field_values( $collection_id, $field_id );
|
||||
$results = $this->metadatum_repository->fetch_all_metadatum_values( $collection_id, $metadatum_id );
|
||||
} else {
|
||||
$results = $this->field_repository->fetch_all_field_values( null, $field_id);
|
||||
$results = $this->metadatum_repository->fetch_all_metadatum_values( null, $metadatum_id);
|
||||
}
|
||||
|
||||
return new \WP_REST_Response($results, 200);
|
||||
}
|
||||
|
||||
$result = $this->field_repository->fetch($field_id, 'OBJECT');
|
||||
$result = $this->metadatum_repository->fetch($metadatum_id, 'OBJECT');
|
||||
|
||||
return new \WP_REST_Response($this->prepare_item_for_response($result, $request), 200);
|
||||
}
|
||||
|
@ -172,11 +172,11 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
|
||||
return true;
|
||||
}
|
||||
} elseif($request['field_id']) {
|
||||
$field = $this->field_repository->fetch($request['field_id']);
|
||||
} elseif($request['metadatum_id']) {
|
||||
$metadatum = $this->metadatum_repository->fetch($request['metadatum_id']);
|
||||
|
||||
if ( $field instanceof Entities\Field ) {
|
||||
if ( $request['context'] === 'edit' && ! $field->can_read() ) {
|
||||
if ( $metadatum instanceof Entities\Metadatum ) {
|
||||
if ( $request['context'] === 'edit' && ! $metadatum->can_read() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -196,22 +196,22 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
* @throws \Exception
|
||||
*/
|
||||
public function prepare_item_for_database( $request, $collection_id = null ) {
|
||||
$field = new Entities\Field();
|
||||
$metadatum = new Entities\Metadatum();
|
||||
|
||||
$meta = json_decode( $request, true );
|
||||
foreach ( $meta as $key => $value ) {
|
||||
$set_ = 'set_' . $key;
|
||||
$field->$set_( $value );
|
||||
$metadatum->$set_( $value );
|
||||
}
|
||||
|
||||
if($collection_id) {
|
||||
$collection = new Entities\Collection( $collection_id );
|
||||
$field->set_collection( $collection );
|
||||
$metadatum->set_collection( $collection );
|
||||
} else {
|
||||
$field->set_collection_id( 'default' );
|
||||
$metadatum->set_collection_id( 'default' );
|
||||
}
|
||||
|
||||
return $field;
|
||||
return $metadatum;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -231,16 +231,16 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
}
|
||||
|
||||
if($prepared->validate()) {
|
||||
$field = $this->field_repository->insert( $prepared);
|
||||
$metadatum = $this->metadatum_repository->insert( $prepared);
|
||||
|
||||
$response = $this->prepare_item_for_response($field, $request);
|
||||
$response = $this->prepare_item_for_response($metadatum, $request);
|
||||
|
||||
return new \WP_REST_Response($response, 201);
|
||||
} else {
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('One or more values are invalid.', 'tainacan'),
|
||||
'errors' => $prepared->get_errors(),
|
||||
'field' => $this->prepare_item_for_response($prepared, $request),
|
||||
'metadatum' => $this->prepare_item_for_response($prepared, $request),
|
||||
], 400);
|
||||
}
|
||||
} elseif (!empty($request->get_body())) {
|
||||
|
@ -251,16 +251,16 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
}
|
||||
|
||||
if ( $prepared->validate() ) {
|
||||
$field = $this->field_repository->insert( $prepared );
|
||||
$metadatum = $this->metadatum_repository->insert( $prepared );
|
||||
|
||||
$response = $this->prepare_item_for_response($field, $request);
|
||||
$response = $this->prepare_item_for_response($metadatum, $request);
|
||||
|
||||
return new \WP_REST_Response($response, 201);
|
||||
} else {
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('One or more values are invalid.', 'tainacan'),
|
||||
'errors' => $prepared->get_errors(),
|
||||
'field' => $this->prepare_item_for_response($prepared, $request),
|
||||
'metadatum' => $this->prepare_item_for_response($prepared, $request),
|
||||
], 400);
|
||||
}
|
||||
|
||||
|
@ -284,7 +284,7 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
return $this->collection_repository->can_edit( new Entities\Collection() );
|
||||
}
|
||||
|
||||
return $this->field_repository->can_edit(new Entities\Field());
|
||||
return $this->metadatum_repository->can_edit(new Entities\Metadatum());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -297,12 +297,12 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
if(!empty($item)){
|
||||
$item_arr = $item->_toArray();
|
||||
|
||||
$item_arr['field_type_object'] = $item->get_field_type_object()->_toArray();
|
||||
$item_arr['metadatum_type_object'] = $item->get_metadatum_type_object()->_toArray();
|
||||
|
||||
if($request['context'] === 'edit'){
|
||||
$item_arr['current_user_can_edit'] = $item->can_edit();
|
||||
ob_start();
|
||||
$item->get_field_type_object()->form();
|
||||
$item->get_metadatum_type_object()->form();
|
||||
$form = ob_get_clean();
|
||||
$item_arr['edit_form'] = $form;
|
||||
$item_arr['enabled'] = $item->get_enabled_for_collection();
|
||||
|
@ -332,7 +332,7 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
|
||||
$collection = new Entities\Collection( $collection_id );
|
||||
|
||||
$result = $this->field_repository->fetch_by_collection( $collection, $args, 'OBJECT' );
|
||||
$result = $this->metadatum_repository->fetch_by_collection( $collection, $args, 'OBJECT' );
|
||||
} else {
|
||||
$args = [
|
||||
'meta_query' => [
|
||||
|
@ -344,7 +344,7 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
]
|
||||
];
|
||||
|
||||
$result = $this->field_repository->fetch( $args, 'OBJECT' );
|
||||
$result = $this->metadatum_repository->fetch( $args, 'OBJECT' );
|
||||
}
|
||||
|
||||
$prepared_item = [];
|
||||
|
@ -362,7 +362,7 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
* @throws \Exception
|
||||
*/
|
||||
public function get_items_permissions_check( $request ) {
|
||||
if ( 'edit' === $request['context'] && ! current_user_can('edit_tainacan-fields') ) {
|
||||
if ( 'edit' === $request['context'] && ! current_user_can('edit_tainacan-metadata') ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -375,11 +375,11 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function delete_item( $request ) {
|
||||
$field_id = $request['field_id'];
|
||||
$metadatum_id = $request['metadatum_id'];
|
||||
|
||||
$field_trashed = $this->field_repository->delete($field_id);
|
||||
$metadatum_trashed = $this->metadatum_repository->delete($metadatum_id);
|
||||
|
||||
$prepared = $this->prepare_item_for_response($field_trashed, $request);
|
||||
$prepared = $this->prepare_item_for_response($metadatum_trashed, $request);
|
||||
|
||||
return new \WP_REST_Response($prepared, 200);
|
||||
}
|
||||
|
@ -399,7 +399,7 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
return $this->field_repository->can_edit(new Entities\Field());
|
||||
return $this->metadatum_repository->can_edit(new Entities\Metadatum());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -414,39 +414,39 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
if(!empty($body)){
|
||||
$attributes = [];
|
||||
|
||||
$field_id = $request['field_id'];
|
||||
$metadatum_id = $request['metadatum_id'];
|
||||
|
||||
foreach ($body as $att => $value){
|
||||
$attributes[$att] = $value;
|
||||
}
|
||||
|
||||
$field = $this->field_repository->fetch($field_id);
|
||||
$metadatum = $this->metadatum_repository->fetch($metadatum_id);
|
||||
|
||||
$error_message = __('Metadata with this ID was not found', 'tainacan');
|
||||
|
||||
if($field){
|
||||
if($metadatum){
|
||||
|
||||
// These conditions are for verify if endpoints are used correctly
|
||||
if(!$collection_id && $field->get_collection_id() !== 'default') {
|
||||
if(!$collection_id && $metadatum->get_collection_id() !== 'default') {
|
||||
$error_message = __('This metadata is not a default metadata', 'tainacan');
|
||||
|
||||
return new \WP_REST_Response( [
|
||||
'error_message' => $error_message,
|
||||
'field_id' => $field_id
|
||||
'metadatum_id' => $metadatum_id
|
||||
] );
|
||||
} elseif ($collection_id && $field->get_collection_id() === 'default'){
|
||||
} elseif ($collection_id && $metadatum->get_collection_id() === 'default'){
|
||||
$error_message = __('This metadata is not a collection metadata', 'tainacan');
|
||||
|
||||
return new \WP_REST_Response( [
|
||||
'error_message' => $error_message,
|
||||
'field_id' => $field_id
|
||||
'metadatum_id' => $metadatum_id
|
||||
] );
|
||||
}
|
||||
|
||||
$prepared_metadata = $this->prepare_item_for_updating($field, $attributes);
|
||||
$prepared_metadata = $this->prepare_item_for_updating($metadatum, $attributes);
|
||||
|
||||
if($prepared_metadata->validate()){
|
||||
$updated_metadata = $this->field_repository->update($prepared_metadata);
|
||||
$updated_metadata = $this->metadatum_repository->update($prepared_metadata);
|
||||
|
||||
$response = $this->prepare_item_for_response($updated_metadata, $request);
|
||||
|
||||
|
@ -456,13 +456,13 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
return new \WP_REST_Response([
|
||||
'error_message' => __('One or more values are invalid.', 'tainacan'),
|
||||
'errors' => $prepared_metadata->get_errors(),
|
||||
'metadata' => $this->prepare_item_for_response($prepared_metadata, $request)
|
||||
'metadatum' => $this->prepare_item_for_response($prepared_metadata, $request)
|
||||
], 400);
|
||||
}
|
||||
|
||||
return new \WP_REST_Response( [
|
||||
'error_message' => $error_message,
|
||||
'field_id' => $field_id
|
||||
'metadatum_id' => $metadatum_id
|
||||
] );
|
||||
}
|
||||
|
||||
|
@ -488,7 +488,7 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
|
||||
}
|
||||
|
||||
return $this->field_repository->can_edit(new Entities\Field());
|
||||
return $this->metadatum_repository->can_edit(new Entities\Metadatum());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -499,7 +499,7 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
public function get_collection_params( $object_name = null ) {
|
||||
$query_params['context']['default'] = 'view';
|
||||
|
||||
$query_params = array_merge($query_params, parent::get_collection_params('field'));
|
||||
$query_params = array_merge($query_params, parent::get_collection_params('metadatum'));
|
||||
|
||||
$query_params['name'] = array(
|
||||
'description' => __('Limits the result set to metadata with a specific name'),
|
||||
|
@ -523,7 +523,7 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
$endpoint_args['fetch'] = [
|
||||
'type' => 'string',
|
||||
'description' => __('Fetch all content of a metadata within a collection'),
|
||||
'enum' => ['all_field_values']
|
||||
'enum' => ['all_metadatum_values']
|
||||
];
|
||||
$endpoint_args['context'] = array(
|
||||
'type' => 'string',
|
||||
|
@ -531,13 +531,13 @@ class REST_Fields_Controller extends REST_Controller {
|
|||
'items' => array( 'view, edit' )
|
||||
);
|
||||
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
|
||||
$map = $this->field_repository->get_map();
|
||||
$map = $this->metadatum_repository->get_map();
|
||||
|
||||
foreach ($map as $mapped => $value){
|
||||
$set_ = 'set_'. $mapped;
|
||||
|
||||
// Show only args that has a method set
|
||||
if( !method_exists(new Entities\Field(), "$set_") ){
|
||||
if( !method_exists(new Entities\Metadatum(), "$set_") ){
|
||||
unset($map[$mapped]);
|
||||
}
|
||||
}
|
|
@ -4,13 +4,13 @@ namespace Tainacan\API\EndPoints;
|
|||
|
||||
use \Tainacan\API\REST_Controller;
|
||||
|
||||
class REST_Field_Mappers_Controller extends REST_Controller {
|
||||
class REST_Metadatum_Mappers_Controller extends REST_Controller {
|
||||
|
||||
/**
|
||||
* REST_Field_Mappers_Controller constructor.
|
||||
* REST_Metadatum_Mappers_Controller constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->rest_base = 'field-mappers';
|
||||
$this->rest_base = 'metadatum-mappers';
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -34,9 +34,9 @@ class REST_Field_Mappers_Controller extends REST_Controller {
|
|||
*/
|
||||
public function prepare_item_for_response( $mapper, $request ) {
|
||||
|
||||
$field_arr = $mapper->_toArray();
|
||||
$metadatum_arr = $mapper->_toArray();
|
||||
|
||||
return $field_arr;
|
||||
return $metadatum_arr;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,11 +47,11 @@ class REST_Field_Mappers_Controller extends REST_Controller {
|
|||
public function get_items( $request ) {
|
||||
$Tainacan_Exposers = \Tainacan\Exposers\Exposers::get_instance();
|
||||
|
||||
$field_mappers = $Tainacan_Exposers->get_mappers( 'OBJECT' );
|
||||
$metadatum_mappers = $Tainacan_Exposers->get_mappers( 'OBJECT' );
|
||||
|
||||
$prepared = [];
|
||||
foreach ($field_mappers as $field_mapper){
|
||||
array_push($prepared, $this->prepare_item_for_response($field_mapper, $request));
|
||||
foreach ($metadatum_mappers as $metadatum_mapper){
|
||||
array_push($prepared, $this->prepare_item_for_response($metadatum_mapper, $request));
|
||||
}
|
||||
|
||||
return new \WP_REST_Response($prepared, 200);
|
|
@ -4,13 +4,13 @@ namespace Tainacan\API\EndPoints;
|
|||
|
||||
use \Tainacan\API\REST_Controller;
|
||||
|
||||
class REST_Field_Types_Controller extends REST_Controller {
|
||||
class REST_Metadatum_Types_Controller extends REST_Controller {
|
||||
|
||||
/**
|
||||
* REST_Field_Types_Controller constructor.
|
||||
* REST_Metadatum_Types_Controller constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->rest_base = 'field-types';
|
||||
$this->rest_base = 'metadatum-types';
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ class REST_Field_Types_Controller extends REST_Controller {
|
|||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
'args' => [
|
||||
'field-type' => [
|
||||
'metadatum-type' => [
|
||||
'description' => __('The structure of objects returned.'),
|
||||
'items' => [
|
||||
'errors' => [
|
||||
|
@ -67,13 +67,13 @@ class REST_Field_Types_Controller extends REST_Controller {
|
|||
* @return mixed|\WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
$name = "\Tainacan\Field_Types\\$item";
|
||||
$field_type = new $name();
|
||||
$name = "\Tainacan\Metadatum_Types\\$item";
|
||||
$metadatum_type = new $name();
|
||||
|
||||
$field_arr = $field_type->_toArray();
|
||||
$field_arr['name'] = $item;
|
||||
$metadatum_arr = $metadatum_type->_toArray();
|
||||
$metadatum_arr['name'] = $item;
|
||||
|
||||
return $field_arr;
|
||||
return $metadatum_arr;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,13 +82,13 @@ class REST_Field_Types_Controller extends REST_Controller {
|
|||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
|
||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
||||
|
||||
$field_types = $Tainacan_Fields->fetch_field_types('NAME');
|
||||
$metadatum_types = $Tainacan_Metadata->fetch_metadatum_types('NAME');
|
||||
|
||||
$prepared = [];
|
||||
foreach ($field_types as $field_type){
|
||||
array_push($prepared, $this->prepare_item_for_response($field_type, $request));
|
||||
foreach ($metadatum_types as $metadatum_type){
|
||||
array_push($prepared, $this->prepare_item_for_response($metadatum_type, $request));
|
||||
}
|
||||
|
||||
return new \WP_REST_Response($prepared, 200);
|
|
@ -5,16 +5,16 @@ const TAINACAN_REST_NAMESPACE = 'tainacan/v2';
|
|||
//$rest_controller = new \Tainacan\API\REST_Controller();
|
||||
$rest_collections_controller = new \Tainacan\API\EndPoints\REST_Collections_Controller();
|
||||
$rest_items_controller = new \Tainacan\API\EndPoints\REST_Items_Controller();
|
||||
$rest_fields_controller = new \Tainacan\API\EndPoints\REST_Fields_Controller();
|
||||
$rest_metadata_controller = new \Tainacan\API\EndPoints\REST_Metadata_Controller();
|
||||
$rest_taxonomies_controller = new \Tainacan\API\EndPoints\REST_Taxonomies_Controller();
|
||||
$rest_terms_controller = new \Tainacan\API\EndPoints\REST_Terms_Controller();
|
||||
$rest_filters_controller = new \Tainacan\API\EndPoints\REST_Filters_Controller();
|
||||
$rest_item_metadata_controller = new \Tainacan\API\EndPoints\REST_Item_Metadata_Controller();
|
||||
$rest_logs_controller = new \Tainacan\API\EndPoints\REST_Logs_Controller();
|
||||
$rest_field_types_controller = new \Tainacan\API\EndPoints\REST_Field_Types_Controller();
|
||||
$rest_metadatum_types_controller = new \Tainacan\API\EndPoints\REST_Metadatum_Types_Controller();
|
||||
$rest_filter_types_controller = new \Tainacan\API\EndPoints\REST_Filter_Types_Controller();
|
||||
new \Tainacan\API\EndPoints\REST_Export_Controller();
|
||||
new \Tainacan\API\EndPoints\REST_Field_Mappers_Controller();
|
||||
new \Tainacan\API\EndPoints\REST_Metadatum_Mappers_Controller();
|
||||
// Add here other endpoints imports
|
||||
|
||||
?>
|
|
@ -47,7 +47,7 @@ class Capabilities {
|
|||
"read"
|
||||
]
|
||||
],
|
||||
"tainacan-field"=> [
|
||||
"tainacan-metadatum"=> [
|
||||
"administrator"=> [
|
||||
"delete_posts",
|
||||
"delete_private_posts",
|
||||
|
|
|
@ -27,7 +27,7 @@ class Collection extends Entity {
|
|||
$columns,
|
||||
$default_view_mode,
|
||||
$enabled_view_modes,
|
||||
$fields_order,
|
||||
$metadata_order,
|
||||
$filters_order,
|
||||
$enable_cover_page,
|
||||
$cover_page_id,
|
||||
|
@ -342,8 +342,8 @@ class Collection extends Entity {
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_default_displayed_fields() {
|
||||
return $this->get_mapped_property( 'default_displayed_fields' );
|
||||
function get_default_displayed_metadata() {
|
||||
return $this->get_mapped_property( 'default_displayed_metadata' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -365,12 +365,12 @@ class Collection extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get collection fields ordination
|
||||
* Get collection metadata ordination
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_fields_order() {
|
||||
return $this->get_mapped_property( 'fields_order' );
|
||||
function get_metadata_order() {
|
||||
return $this->get_mapped_property( 'metadata_order' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -439,34 +439,34 @@ class Collection extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get collection field.
|
||||
* Get collection metadatum.
|
||||
*
|
||||
* Returns an array of \Entity\Field objects, representing all the field of the collection.
|
||||
* Returns an array of \Entity\Metadatum objects, representing all the metadatum of the collection.
|
||||
*
|
||||
* @see \Tainacan\Repositories\Fields->fetch()
|
||||
* @see \Tainacan\Repositories\Metadata->fetch()
|
||||
*
|
||||
* @return [\Tainacan\Entities\Field] array
|
||||
* @return [\Tainacan\Entities\Metadatum] array
|
||||
* @throws \Exception
|
||||
*/
|
||||
function get_fields() {
|
||||
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
|
||||
function get_metadata() {
|
||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
||||
|
||||
return $Tainacan_Fields->fetch_by_collection( $this, [], 'OBJECT' );
|
||||
return $Tainacan_Metadata->fetch_by_collection( $this, [], 'OBJECT' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the two core fields of the collection (title and description)
|
||||
* Get the two core metadata of the collection (title and description)
|
||||
*
|
||||
* @return array[\Tainacan\Entities\Field]
|
||||
* @return array[\Tainacan\Entities\Metadatum]
|
||||
*/
|
||||
function get_core_fields() {
|
||||
$repo = \Tainacan\Repositories\Fields::get_instance();
|
||||
function get_core_metadata() {
|
||||
$repo = \Tainacan\Repositories\Metadata::get_instance();
|
||||
|
||||
return $repo->fetch_by_collection($this, [
|
||||
'meta_query' => [
|
||||
[
|
||||
'key' => 'field_type',
|
||||
'value' => ['Tainacan\Field_Types\Core_Title', 'Tainacan\Field_Types\Core_Description'],
|
||||
'key' => 'metadatum_type',
|
||||
'value' => ['Tainacan\Metadatum_Types\Core_Title', 'Tainacan\Metadatum_Types\Core_Description'],
|
||||
'compare' => 'IN'
|
||||
]
|
||||
]
|
||||
|
@ -474,48 +474,48 @@ class Collection extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the Core Title Field for this collection
|
||||
* Get the Core Title Metadatum for this collection
|
||||
*
|
||||
* @return \Tainacan\Entities\Field The Core Title Field
|
||||
* @return \Tainacan\Entities\Metadatum The Core Title Metadatum
|
||||
*/
|
||||
function get_core_title_field() {
|
||||
$repo = \Tainacan\Repositories\Fields::get_instance();
|
||||
function get_core_title_metadatum() {
|
||||
$repo = \Tainacan\Repositories\Metadata::get_instance();
|
||||
|
||||
$results = $repo->fetch_by_collection($this, [
|
||||
'meta_query' => [
|
||||
[
|
||||
'key' => 'field_type',
|
||||
'value' => 'Tainacan\Field_Types\Core_Title',
|
||||
'key' => 'metadatum_type',
|
||||
'value' => 'Tainacan\Metadatum_Types\Core_Title',
|
||||
]
|
||||
],
|
||||
'posts_per_page' => 1
|
||||
], 'OBJECT');
|
||||
|
||||
if (is_array($results) && sizeof($results) == 1 && $results[0] instanceof \Tainacan\Entities\Field) {
|
||||
if (is_array($results) && sizeof($results) == 1 && $results[0] instanceof \Tainacan\Entities\Metadatum) {
|
||||
return $results[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Core Description Field for this collection
|
||||
* Get the Core Description Metadatum for this collection
|
||||
*
|
||||
* @return \Tainacan\Entities\Field The Core Description Field
|
||||
* @return \Tainacan\Entities\Metadatum The Core Description Metadatum
|
||||
*/
|
||||
function get_core_description_field() {
|
||||
$repo = \Tainacan\Repositories\Fields::get_instance();
|
||||
function get_core_description_metadatum() {
|
||||
$repo = \Tainacan\Repositories\Metadata::get_instance();
|
||||
|
||||
$results = $repo->fetch_by_collection($this, [
|
||||
'meta_query' => [
|
||||
[
|
||||
'key' => 'field_type',
|
||||
'value' => 'Tainacan\Field_Types\Core_Description',
|
||||
'key' => 'metadatum_type',
|
||||
'value' => 'Tainacan\Metadatum_Types\Core_Description',
|
||||
]
|
||||
],
|
||||
'posts_per_page' => 1
|
||||
], 'OBJECT');
|
||||
|
||||
if (is_array($results) && sizeof($results) == 1 && $results[0] instanceof \Tainacan\Entities\Field) {
|
||||
if (is_array($results) && sizeof($results) == 1 && $results[0] instanceof \Tainacan\Entities\Metadatum) {
|
||||
return $results[0];
|
||||
}
|
||||
return false;
|
||||
|
@ -611,8 +611,8 @@ class Collection extends Entity {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function set_default_displayed_fields( $value ) {
|
||||
$this->set_mapped_property( 'default_displayed_fields', $value );
|
||||
function set_default_displayed_metadata( $value ) {
|
||||
$this->set_mapped_property( 'default_displayed_metadata', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -638,14 +638,14 @@ class Collection extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set collection fields ordination
|
||||
* Set collection metadata ordination
|
||||
*
|
||||
* @param [string] $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function set_fields_order( $value ) {
|
||||
$this->set_mapped_property( 'fields_order', $value );
|
||||
function set_metadata_order( $value ) {
|
||||
$this->set_mapped_property( 'metadata_order', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,7 +15,7 @@ class Filter extends Entity {
|
|||
$description,
|
||||
$order,
|
||||
$color,
|
||||
$field,
|
||||
$metadatum,
|
||||
$filter_type,
|
||||
$filter_type_options;
|
||||
|
||||
|
@ -39,11 +39,11 @@ class Filter extends Entity {
|
|||
*/
|
||||
public function _toArray(){
|
||||
$filter_array = parent::_toArray();
|
||||
$field_id = $filter_array['field'];
|
||||
$metadatum_id = $filter_array['metadatum'];
|
||||
|
||||
$filter_array['field'] = [];
|
||||
$filter_array['field']['field_id'] = $field_id;
|
||||
$filter_array['field']['field_name'] = $this->get_field()->get_name();
|
||||
$filter_array['metadatum'] = [];
|
||||
$filter_array['metadatum']['metadatum_id'] = $metadatum_id;
|
||||
$filter_array['metadatum']['metadatum_name'] = $this->get_metadatum()->get_name();
|
||||
|
||||
return $filter_array;
|
||||
}
|
||||
|
@ -83,14 +83,14 @@ class Filter extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the field
|
||||
* Return the metadatum
|
||||
*
|
||||
* @return Field
|
||||
* @return Metadatum
|
||||
* @throws \Exception
|
||||
*/
|
||||
function get_field() {
|
||||
$id = $this->get_mapped_property('field');
|
||||
return new Field( $id );
|
||||
function get_metadatum() {
|
||||
$id = $this->get_mapped_property('metadatum');
|
||||
return new Metadatum( $id );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -169,15 +169,15 @@ class Filter extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Define the filter field
|
||||
* Define the filter metadatum
|
||||
*
|
||||
* @param \Tainacan\Entities\Field
|
||||
* @param \Tainacan\Entities\Metadatum
|
||||
* @return void
|
||||
*/
|
||||
function set_field( $value ){
|
||||
$id = ( $value instanceof Field ) ? $value->get_id() : $value;
|
||||
function set_metadatum( $value ){
|
||||
$id = ( $value instanceof Metadatum ) ? $value->get_id() : $value;
|
||||
|
||||
$this->set_mapped_property('field', $id);
|
||||
$this->set_mapped_property('metadatum', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -193,7 +193,7 @@ class Filter extends Entity {
|
|||
/**
|
||||
* Transient property used to store the status of the filter for a particular collection
|
||||
*
|
||||
* Used by the API to tell front end when a field is disabled
|
||||
* Used by the API to tell front end when a metadatum is disabled
|
||||
*
|
||||
*/
|
||||
public function get_enabled_for_collection() {
|
||||
|
@ -207,7 +207,7 @@ class Filter extends Entity {
|
|||
/**
|
||||
* {@inheritdoc }
|
||||
*
|
||||
* Also validates the field, calling the validate_options callback of the Field Type
|
||||
* Also validates the metadatum, calling the validate_options callback of the Metadatum Type
|
||||
*
|
||||
* @return bool valid or not
|
||||
* @throws \Exception
|
||||
|
@ -228,11 +228,11 @@ class Filter extends Entity {
|
|||
}
|
||||
|
||||
if (!is_array($is_valid)) {
|
||||
throw new \Exception( "Return of validate_options field type method should be an Array in case of error" );
|
||||
throw new \Exception( "Return of validate_options metadatum type method should be an Array in case of error" );
|
||||
}
|
||||
|
||||
foreach ($is_valid as $field => $message) {
|
||||
$this->add_error($field, $message);
|
||||
foreach ($is_valid as $metadatum => $message) {
|
||||
$this->add_error($metadatum, $message);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace Tainacan\Entities;
|
|||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Represents the Item Field Entity
|
||||
* Represents the Item Metadatum Entity
|
||||
*/
|
||||
class Item_Metadata_Entity extends Entity {
|
||||
protected static $post_type = false;
|
||||
|
@ -18,7 +18,7 @@ class Item_Metadata_Entity extends Entity {
|
|||
|
||||
protected
|
||||
$item,
|
||||
$field,
|
||||
$metadatum,
|
||||
$parent_meta_id,
|
||||
$meta_id,
|
||||
$has_value,
|
||||
|
@ -27,13 +27,13 @@ class Item_Metadata_Entity extends Entity {
|
|||
/**
|
||||
*
|
||||
* @param Item $item Item Entity
|
||||
* @param Field $field Field Entity
|
||||
* @param Metadatum $metadatum Metadatum Entity
|
||||
* @param int $meta_id ID for a specific meta row
|
||||
*/
|
||||
function __construct(Item $item = null, Field $field = null, $meta_id = null, $parent_meta_id = null) {
|
||||
function __construct(Item $item = null, Metadatum $metadatum = null, $meta_id = null, $parent_meta_id = null) {
|
||||
|
||||
$this->set_item($item);
|
||||
$this->set_field($field);
|
||||
$this->set_metadatum($metadatum);
|
||||
|
||||
if (!is_null($meta_id) && is_int($meta_id)) {
|
||||
$this->set_meta_id($meta_id);
|
||||
|
@ -51,10 +51,10 @@ class Item_Metadata_Entity extends Entity {
|
|||
* @return string
|
||||
*/
|
||||
public function get_value_as_html(){
|
||||
$field = $this->get_field();
|
||||
$metadatum = $this->get_metadatum();
|
||||
|
||||
if (is_object($field)) {
|
||||
$fto = $field->get_field_type_object();
|
||||
if (is_object($metadatum)) {
|
||||
$fto = $metadatum->get_metadatum_type_object();
|
||||
if (is_object($fto)) {
|
||||
|
||||
if ( method_exists($fto, 'get_value_as_html') ) {
|
||||
|
@ -143,12 +143,12 @@ class Item_Metadata_Entity extends Entity {
|
|||
$as_array['value_as_html'] = $this->get_value_as_html();
|
||||
$as_array['value_as_string'] = $this->get_value_as_string();
|
||||
|
||||
if($this->get_field()->get_field_type_object()->get_primitive_type() === 'date'){
|
||||
if($this->get_metadatum()->get_metadatum_type_object()->get_primitive_type() === 'date'){
|
||||
$as_array['date_i18n'] = $this->get_date_i18n($this->get_value_as_string());
|
||||
}
|
||||
|
||||
$as_array['item'] = $this->get_item()->_toArray();
|
||||
$as_array['field'] = $this->get_field()->_toArray();
|
||||
$as_array['metadatum'] = $this->get_metadatum()->_toArray();
|
||||
|
||||
return $as_array;
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ class Item_Metadata_Entity extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Define the field value
|
||||
* Define the metadatum value
|
||||
*
|
||||
* @param [integer | string] $value
|
||||
* @return void
|
||||
|
@ -174,20 +174,20 @@ class Item_Metadata_Entity extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Define the field
|
||||
* Define the metadatum
|
||||
*
|
||||
* @param Field $field
|
||||
* @param Metadatum $metadatum
|
||||
* @return void
|
||||
*/
|
||||
function set_field(Field $field = null) {
|
||||
$this->field = $field;
|
||||
function set_metadatum(Metadatum $metadatum = null) {
|
||||
$this->metadatum = $metadatum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the specific meta ID for this metadata.
|
||||
*
|
||||
* When this value is set, get_value() will use it to fetch the value from
|
||||
* the post_meta table, instead of considering the item and field IDs
|
||||
* the post_meta table, instead of considering the item and metadatum IDs
|
||||
*
|
||||
* @param int $meta_id the ID of a specifica post_meta row
|
||||
*/
|
||||
|
@ -195,15 +195,15 @@ class Item_Metadata_Entity extends Entity {
|
|||
if (is_int($meta_id)) {
|
||||
$this->meta_id = $meta_id;
|
||||
return true;
|
||||
// TODO: Should we check here to see if this meta_id is really from this field and item?
|
||||
// TODO: Should we check here to see if this meta_id is really from this metadatum and item?
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set parent_meta_id. Used when a item_metadata is inside a compound Field
|
||||
* Set parent_meta_id. Used when a item_metadata is inside a compound Metadatum
|
||||
*
|
||||
* When you have a multiple compound field, this indicates of which instace of the value this item_metadata is attached to
|
||||
* When you have a multiple compound metadatum, this indicates of which instace of the value this item_metadata is attached to
|
||||
*
|
||||
* @param [type] $parent_meta_id [description]
|
||||
*/
|
||||
|
@ -211,7 +211,7 @@ class Item_Metadata_Entity extends Entity {
|
|||
if (is_int($parent_meta_id)) {
|
||||
$this->parent_meta_id = $parent_meta_id;
|
||||
return true;
|
||||
// TODO: Should we check here to see if this meta_id is really from this field and item?
|
||||
// TODO: Should we check here to see if this meta_id is really from this metadatum and item?
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -226,18 +226,18 @@ class Item_Metadata_Entity extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the field
|
||||
* Return the metadatum
|
||||
*
|
||||
* @return Field
|
||||
* @return Metadatum
|
||||
*/
|
||||
function get_field() {
|
||||
return $this->field;
|
||||
function get_metadatum() {
|
||||
return $this->metadatum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the meta_id
|
||||
*
|
||||
* @return Field
|
||||
* @return Metadatum
|
||||
*/
|
||||
function get_meta_id() {
|
||||
return isset($this->meta_id) ? $this->meta_id : null;
|
||||
|
@ -246,14 +246,14 @@ class Item_Metadata_Entity extends Entity {
|
|||
/**
|
||||
* Return the meta_id
|
||||
*
|
||||
* @return Field
|
||||
* @return Metadatum
|
||||
*/
|
||||
function get_parent_meta_id() {
|
||||
return isset($this->parent_meta_id) ? $this->parent_meta_id : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the field value
|
||||
* Return the metadatum value
|
||||
*
|
||||
* @return string | integer
|
||||
*/
|
||||
|
@ -280,30 +280,30 @@ class Item_Metadata_Entity extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return true if field is multiple, else return false
|
||||
* Return true if metadatum is multiple, else return false
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function is_multiple() {
|
||||
return $this->get_field()->is_multiple();
|
||||
return $this->get_metadatum()->is_multiple();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if field is key
|
||||
* Return true if metadatum is key
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function is_collection_key() {
|
||||
return $this->get_field()->is_collection_key();
|
||||
return $this->get_metadatum()->is_collection_key();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if field is required
|
||||
* Return true if metadatum is required
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function is_required() {
|
||||
return $this->get_field()->is_required();
|
||||
return $this->get_metadatum()->is_required();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -313,19 +313,19 @@ class Item_Metadata_Entity extends Entity {
|
|||
*/
|
||||
function validate() {
|
||||
$value = $this->get_value();
|
||||
$field = $this->get_field();
|
||||
$metadatum = $this->get_metadatum();
|
||||
$item = $this->get_item();
|
||||
|
||||
if (empty($value) && $this->is_required()) {
|
||||
$this->add_error('required', $field->get_name() . ' is required');
|
||||
$this->add_error('required', $metadatum->get_name() . ' is required');
|
||||
return false;
|
||||
}
|
||||
|
||||
$classFieldType = $field->get_field_type_object();
|
||||
if( is_object( $classFieldType ) ){
|
||||
if( method_exists ( $classFieldType , 'validate' ) ){
|
||||
if( ! $classFieldType->validate( $this ) ) {
|
||||
$this->add_error('field_type_error', $classFieldType->get_errors() );
|
||||
$classMetadatumType = $metadatum->get_metadatum_type_object();
|
||||
if( is_object( $classMetadatumType ) ){
|
||||
if( method_exists ( $classMetadatumType , 'validate' ) ){
|
||||
if( ! $classMetadatumType->validate( $this ) ) {
|
||||
$this->add_error('metadatum_type_error', $classMetadatumType->get_errors() );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -344,25 +344,25 @@ class Item_Metadata_Entity extends Entity {
|
|||
}
|
||||
|
||||
if ($this->is_required() && !$one_filled) {
|
||||
$this->add_error('required', $field->get_name() . ' is required');
|
||||
$this->add_error('required', $metadatum->get_name() . ' is required');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$valid) {
|
||||
$this->add_error('invalid', $field->get_name() . ' is invalid');
|
||||
$this->add_error('invalid', $metadatum->get_name() . ' is invalid');
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->set_as_valid();
|
||||
return true;
|
||||
} else {
|
||||
$this->add_error('invalid', $field->get_name() . ' is invalid');
|
||||
$this->add_error('invalid', $metadatum->get_name() . ' is invalid');
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
||||
if( is_array($value) ){
|
||||
$this->add_error('not_multiple', $field->get_name() . ' do not accept array as value');
|
||||
$this->add_error('not_multiple', $metadatum->get_name() . ' do not accept array as value');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -372,7 +372,7 @@ class Item_Metadata_Entity extends Entity {
|
|||
$test = $Tainacan_Items->fetch([
|
||||
'meta_query' => [
|
||||
[
|
||||
'key' => $this->field->get_id(),
|
||||
'key' => $this->metadatum->get_id(),
|
||||
'value' => $value
|
||||
],
|
||||
],
|
||||
|
@ -380,7 +380,7 @@ class Item_Metadata_Entity extends Entity {
|
|||
], $item->get_collection());
|
||||
|
||||
if ($test->have_posts()) {
|
||||
$this->add_error('key_exists', $field->get_name() . ' is a collection key and there is another item with the same value');
|
||||
$this->add_error('key_exists', $metadatum->get_name() . ' is a collection key and there is another item with the same value');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -336,13 +336,13 @@ class Item extends Entity {
|
|||
/**
|
||||
* Return a List of ItemMetadata objects
|
||||
*
|
||||
* It will return all fields associeated with the collection this item is part of.
|
||||
* It will return all metadata associeated with the collection this item is part of.
|
||||
*
|
||||
* If the item already has a value for any of the fields, it will be available.
|
||||
* If the item already has a value for any of the metadata, it will be available.
|
||||
*
|
||||
* @return array Array of ItemMetadata objects
|
||||
*/
|
||||
function get_fields($args = []) {
|
||||
function get_metadata($args = []) {
|
||||
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
|
||||
|
||||
return $Tainacan_Item_Metadata->fetch( $this, 'OBJECT', $args );
|
||||
|
@ -380,18 +380,18 @@ class Item extends Entity {
|
|||
$is_valid = false;
|
||||
}
|
||||
|
||||
$arrayItemMetadata = $this->get_fields();
|
||||
$arrayItemMetadata = $this->get_metadata();
|
||||
if ( $arrayItemMetadata ) {
|
||||
foreach ( $arrayItemMetadata as $itemMetadata ) {
|
||||
|
||||
// skip validation for Compound Fields
|
||||
if ( $itemMetadata->get_field()->get_field_type() == 'Tainacan\Field_Types\Compound' ) {
|
||||
// skip validation for Compound Metadata
|
||||
if ( $itemMetadata->get_metadatum()->get_metadatum_type() == 'Tainacan\Metadatum_Types\Compound' ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! $itemMetadata->validate() ) {
|
||||
$errors = $itemMetadata->get_errors();
|
||||
$this->add_error( $itemMetadata->get_field()->get_id(), $errors );
|
||||
$this->add_error( $itemMetadata->get_metadatum()->get_id(), $errors );
|
||||
$is_valid = false;
|
||||
}
|
||||
}
|
||||
|
@ -410,7 +410,7 @@ class Item extends Entity {
|
|||
* {@inheritDoc}
|
||||
* @see \Tainacan\Entities\Entity::validate()
|
||||
*/
|
||||
public function validate_core_fields() {
|
||||
public function validate_core_metadata() {
|
||||
if ( ! in_array( $this->get_status(), apply_filters( 'tainacan-status-require-validation', [
|
||||
'publish',
|
||||
'future',
|
||||
|
@ -449,15 +449,15 @@ class Item extends Entity {
|
|||
/**
|
||||
* Return the item metadata as a HTML string to be used as output.
|
||||
*
|
||||
* Each metadata is a label with the field name and the value.
|
||||
* Each metadata is a label with the metadatum name and the value.
|
||||
*
|
||||
* If an ID, a slug or a Tainacan\Entities\Field object is passed in the 'metadata' argument, it returns only one metadata, otherwise
|
||||
* If an ID, a slug or a Tainacan\Entities\Metadatum object is passed in the 'metadata' argument, it returns only one metadata, otherwise
|
||||
* it returns all metadata
|
||||
*
|
||||
* @param array|string $args {
|
||||
* Optional. Array or string of arguments.
|
||||
*
|
||||
* @type mixed $metadata Field object, ID or slug to retrieve only one field. empty returns all metadata
|
||||
* @type mixed $metadata Metadatum object, ID or slug to retrieve only one metadatum. empty returns all metadata
|
||||
*
|
||||
* @type array $metadata__in Array of metadata IDs or Slugs to be retrieved. Default none
|
||||
*
|
||||
|
@ -469,7 +469,7 @@ class Item extends Entity {
|
|||
*
|
||||
* @type bool $exclude_core Exclude Core Metadata (title and description) from result. Default false
|
||||
*
|
||||
* @type bool $hide_empty Wether to hide or not fields the item has no value to
|
||||
* @type bool $hide_empty Wether to hide or not metadata the item has no value to
|
||||
* Default: true
|
||||
* @type string $before_title String to be added before each metadata title
|
||||
* Default '<h3>'
|
||||
|
@ -487,7 +487,7 @@ class Item extends Entity {
|
|||
public function get_metadata_as_html($args = array()) {
|
||||
|
||||
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
|
||||
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
|
||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
||||
|
||||
$return = '';
|
||||
|
||||
|
@ -508,33 +508,33 @@ class Item extends Entity {
|
|||
|
||||
if (!is_null($args['metadata'])) {
|
||||
|
||||
$field_object = null;
|
||||
$metadatum_object = null;
|
||||
|
||||
if ( $field instanceof \Tainacan\Entities\Field ) {
|
||||
$field_object = $field;
|
||||
} elseif ( is_int($field) ) {
|
||||
$field_object = $Tainacan_Fields->fetch($field);
|
||||
} elseif ( is_string($field) ) {
|
||||
$query = $Tainacan_Fields->fetch(['slug' => $field], 'OBJECT');
|
||||
if ( is_array($query) && sizeof($query) == 1 && isset($field[0])) {
|
||||
$field_object = $field[0];
|
||||
if ( $metadatum instanceof \Tainacan\Entities\Metadatum ) {
|
||||
$metadatum_object = $metadatum;
|
||||
} elseif ( is_int($metadatum) ) {
|
||||
$metadatum_object = $Tainacan_Metadata->fetch($metadatum);
|
||||
} elseif ( is_string($metadatum) ) {
|
||||
$query = $Tainacan_Metadata->fetch(['slug' => $metadatum], 'OBJECT');
|
||||
if ( is_array($query) && sizeof($query) == 1 && isset($metadatum[0])) {
|
||||
$metadatum_object = $metadatum[0];
|
||||
}
|
||||
}
|
||||
|
||||
if ( $field_object instanceof \Tainacan\Entities\Field ) {
|
||||
if ( $metadatum_object instanceof \Tainacan\Entities\Metadatum ) {
|
||||
|
||||
if ( is_array($args['metadata__not_in'])
|
||||
&& (
|
||||
in_array($field_object->get_slug(), $args['metadata__not_in']) ||
|
||||
in_array($field_object->get_id(), $args['metadata__not_in'])
|
||||
in_array($metadatum_object->get_slug(), $args['metadata__not_in']) ||
|
||||
in_array($metadatum_object->get_id(), $args['metadata__not_in'])
|
||||
)
|
||||
) {
|
||||
return $return;
|
||||
}
|
||||
|
||||
$item_meta = new \Tainacan\Entities\Item_Metadata_Entity($this, $field_object);
|
||||
$item_meta = new \Tainacan\Entities\Item_Metadata_Entity($this, $metadatum_object);
|
||||
if ($item_meta->has_value() || !$args['hide_empty']) {
|
||||
$return .= $args['before_title'] . $field_object->get_name() . $args['after_title'];
|
||||
$return .= $args['before_title'] . $metadatum_object->get_name() . $args['after_title'];
|
||||
$return .= $args['before_value'] . $item_meta->get_value_as_html() . $args['after_value'];
|
||||
}
|
||||
|
||||
|
@ -578,11 +578,11 @@ class Item extends Entity {
|
|||
}
|
||||
|
||||
|
||||
$fields = $this->get_fields($query_args);
|
||||
$metadata = $this->get_metadata($query_args);
|
||||
|
||||
foreach ( $fields as $item_meta ) {
|
||||
foreach ( $metadata as $item_meta ) {
|
||||
|
||||
$fto = $item_meta->get_field()->get_field_type_object();
|
||||
$fto = $item_meta->get_metadatum()->get_metadatum_type_object();
|
||||
|
||||
if ( $fto->get_core() ) {
|
||||
if ( $args['exclude_core'] ) {
|
||||
|
@ -595,7 +595,7 @@ class Item extends Entity {
|
|||
}
|
||||
|
||||
if ($item_meta->has_value() || !$args['hide_empty']) {
|
||||
$return .= $args['before_title'] . $item_meta->get_field()->get_name() . $args['after_title'];
|
||||
$return .= $args['before_title'] . $item_meta->get_metadatum()->get_name() . $args['after_title'];
|
||||
$return .= $args['before_value'] . $item_meta->get_value_as_html() . $args['after_value'];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@ namespace Tainacan\Entities;
|
|||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Represents the Entity Field
|
||||
* Represents the Entity Metadatum
|
||||
*/
|
||||
class Field extends Entity {
|
||||
class Metadatum extends Entity {
|
||||
protected
|
||||
$name,
|
||||
$slug,
|
||||
|
@ -21,21 +21,31 @@ class Field extends Entity {
|
|||
$collection_key,
|
||||
$mask,
|
||||
$default_value,
|
||||
$field_type,
|
||||
$field_type_options;
|
||||
$metadatum_type,
|
||||
$metadatum_type_options;
|
||||
|
||||
// Collection getter and setter declared here
|
||||
use \Tainacan\Traits\Entity_Collection_Relation;
|
||||
|
||||
public $enabled_for_collection = true;
|
||||
|
||||
static $post_type = 'tainacan-field';
|
||||
static $post_type = 'tainacan-metadatum';
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see \Tainacan\Entities\Entity::capability_type
|
||||
* @var string
|
||||
*/
|
||||
protected static $capability_type = ['tainacan-metadatum', 'tainacan-metadata'];
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see \Tainacan\Entities\Entity::repository
|
||||
* @var string
|
||||
*/
|
||||
protected $repository = 'Fields';
|
||||
protected $repository = 'Metadata';
|
||||
|
||||
public function __toString(){
|
||||
return 'Hello, my name is '. $this->get_name();
|
||||
|
@ -57,7 +67,7 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the field name
|
||||
* Return the metadatum name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
@ -66,7 +76,7 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get field slug
|
||||
* Get metadatum slug
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
@ -75,7 +85,7 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the field order type
|
||||
* Return the metadatum order type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
@ -93,7 +103,7 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the field description
|
||||
* Return the metadatum description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
@ -102,7 +112,7 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return if is a required field
|
||||
* Return if is a required metadatum
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
|
@ -111,7 +121,7 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return if is a multiple field
|
||||
* Return if is a multiple metadatum
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
|
@ -129,7 +139,7 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return if field is key
|
||||
* Return if metadatum is key
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
|
@ -147,7 +157,7 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the field default value
|
||||
* Return the metadatum default value
|
||||
*
|
||||
* @return string || integer
|
||||
*/
|
||||
|
@ -156,37 +166,37 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the an object child of \Tainacan\Field_Types\Field_Type with options
|
||||
* Return the an object child of \Tainacan\metadatum_Types\Metadatum_Type with options
|
||||
*
|
||||
* @return \Tainacan\Field_Types\Field_Type The field type class with filled options
|
||||
* @return \Tainacan\Metadatum_Types\Metadatum_Type The metadatum type class with filled options
|
||||
*/
|
||||
function get_field_type_object(){
|
||||
$class_name = $this->get_field_type();
|
||||
function get_metadatum_type_object(){
|
||||
$class_name = $this->get_metadatum_type();
|
||||
$object_type = new $class_name();
|
||||
$object_type->set_options( $this->get_field_type_options() );
|
||||
$object_type->set_options( $this->get_metadatum_type_options() );
|
||||
return $object_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class name for the field type
|
||||
* Return the class name for the metadatum type
|
||||
*
|
||||
* @return string The
|
||||
*/
|
||||
function get_field_type(){
|
||||
return $this->get_mapped_property('field_type');
|
||||
function get_metadatum_type(){
|
||||
return $this->get_mapped_property('metadatum_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the actual options for the current field type
|
||||
* Return the actual options for the current metadatum type
|
||||
*
|
||||
* @return array Configurations for the field type object
|
||||
* @return array Configurations for the metadatum type object
|
||||
*/
|
||||
function get_field_type_options(){
|
||||
return $this->get_mapped_property('field_type_options');
|
||||
function get_metadatum_type_options(){
|
||||
return $this->get_mapped_property('metadatum_type_options');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this field allow community suggestions, false otherwise
|
||||
* Return true if this metadatum allow community suggestions, false otherwise
|
||||
* @return bool
|
||||
*/
|
||||
function get_accept_suggestion() {
|
||||
|
@ -202,7 +212,7 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the field name
|
||||
* Set the metadatum name
|
||||
*
|
||||
* @param [string] $value
|
||||
* @return void
|
||||
|
@ -212,9 +222,9 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the field slug
|
||||
* Set the metadatum slug
|
||||
*
|
||||
* If you dont set the field slug, it will be set automatically based on the name and
|
||||
* If you dont set the metadatum slug, it will be set automatically based on the name and
|
||||
* following WordPress default behavior of creating slugs for posts.
|
||||
*
|
||||
* If you set the slug for an existing one, WordPress will append a number at the end of in order
|
||||
|
@ -228,7 +238,7 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set manually the order of the field
|
||||
* Set manually the order of the metadatum
|
||||
*
|
||||
* @param [string] $value
|
||||
* @return void
|
||||
|
@ -238,7 +248,7 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the field parent ID
|
||||
* Set the metadatum parent ID
|
||||
*
|
||||
* @param [integer] $value The ID from parent
|
||||
* @return void
|
||||
|
@ -248,7 +258,7 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set field description
|
||||
* Set metadatum description
|
||||
*
|
||||
* @param [string] $value The text description
|
||||
* @return void
|
||||
|
@ -258,7 +268,7 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Allow the field be required
|
||||
* Allow the metadatum be required
|
||||
*
|
||||
* @param [boolean] $value
|
||||
* @return void
|
||||
|
@ -268,7 +278,7 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Allow multiple fields
|
||||
* Allow multiple metadata
|
||||
*
|
||||
* @param [boolean] $value
|
||||
* @return void
|
||||
|
@ -278,7 +288,7 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* The number of possible fields
|
||||
* The number of possible metadata
|
||||
*
|
||||
* @param [string] $value
|
||||
* @return void
|
||||
|
@ -298,7 +308,7 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set mask for the field
|
||||
* Set mask for the metadatum
|
||||
*
|
||||
* @param [string] $value
|
||||
* @return void
|
||||
|
@ -318,16 +328,16 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* set the field type class name
|
||||
* set the metadatum type class name
|
||||
*
|
||||
* @param string | \Tainacan\Field_Types\Field_Type $value The name of the class or the instance
|
||||
* @param string | \Tainacan\Metadatum_Types\Metadatum_Type $value The name of the class or the instance
|
||||
*/
|
||||
public function set_field_type( $value ){
|
||||
$this->set_mapped_property('field_type', ( is_object( $value ) ) ? get_class( $value ) : $value ) ; // Encode to avoid backslaches removal
|
||||
public function set_metadatum_type( $value ){
|
||||
$this->set_mapped_property('metadatum_type', ( is_object( $value ) ) ? get_class( $value ) : $value ) ; // Encode to avoid backslaches removal
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if this field allow community suggestions
|
||||
* Set if this metadatum allow community suggestions
|
||||
* @param bool $value
|
||||
*/
|
||||
function set_accept_suggestion( $value ) {
|
||||
|
@ -335,17 +345,17 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set Field type options
|
||||
* Set Metadatum type options
|
||||
*
|
||||
* @param [string || integer] $value
|
||||
* @return void
|
||||
*/
|
||||
function set_field_type_options( $value ){
|
||||
$this->set_mapped_property('field_type_options', $value);
|
||||
function set_metadatum_type_options( $value ){
|
||||
$this->set_mapped_property('metadatum_type_options', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set exposers mapping configuration for this field
|
||||
* Set exposers mapping configuration for this metadatum
|
||||
* @param array $value
|
||||
*/
|
||||
public function set_exposer_mapping( $value ) {
|
||||
|
@ -354,9 +364,9 @@ class Field extends Entity {
|
|||
|
||||
|
||||
/**
|
||||
* Transient property used to store the status of the field for a particular collection
|
||||
* Transient property used to store the status of the metadatum for a particular collection
|
||||
*
|
||||
* Used by the API to tell front end when a field is disabled
|
||||
* Used by the API to tell front end when a metadatum is disabled
|
||||
*
|
||||
*/
|
||||
public function get_enabled_for_collection() {
|
||||
|
@ -399,7 +409,7 @@ class Field extends Entity {
|
|||
/**
|
||||
* {@inheritdoc }
|
||||
*
|
||||
* Also validates the field, calling the validate_options callback of the Field Type
|
||||
* Also validates the metadatum, calling the validate_options callback of the Metadatum Type
|
||||
*
|
||||
* @return bool valid or not
|
||||
* @throws \Exception
|
||||
|
@ -411,28 +421,28 @@ class Field extends Entity {
|
|||
if (false === $is_valid)
|
||||
return false;
|
||||
|
||||
// You cant have a multiple field inside a compound field (except category)
|
||||
// You cant have a multiple metadatum inside a compound metadatum (except category)
|
||||
if ($this->get_parent() > 0) {
|
||||
if ( $this->is_multiple() && $this->get_field_type_object()->get_primitive_type() != 'term') {
|
||||
if ( $this->is_multiple() && $this->get_metadatum_type_object()->get_primitive_type() != 'term') {
|
||||
$this->add_error($this->get_id(), __('Compound metadata do not support metadata with multiple values (except categories)', 'tainacan'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// You cant have a category field inside a multiple compound field
|
||||
if ( $this->get_parent() > 0 && $this->get_field_type_object()->get_primitive_type() == 'term' ) {
|
||||
$parent_field = new \Tainacan\Entities\Field($this->get_parent());
|
||||
if ( $parent_field->is_multiple() ) {
|
||||
// You cant have a category metadatum inside a multiple compound metadatum
|
||||
if ( $this->get_parent() > 0 && $this->get_metadatum_type_object()->get_primitive_type() == 'term' ) {
|
||||
$parent_metadatum = new \Tainacan\Entities\Metadatum($this->get_parent());
|
||||
if ( $parent_metadatum->is_multiple() ) {
|
||||
$this->add_error($this->get_id(), __('Taxonomy metadata can not be used inside Compound metadata with multiple values', 'tainacan'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( $this->get_field_type() == 'Tainacan\Field_Types\Compound' && $this->is_multiple() ) {
|
||||
$Tainacan_fields = \Tainacan\Repositories\Fields::get_instance();
|
||||
$children = $Tainacan_fields->fetch(
|
||||
if ( $this->get_metadatum_type() == 'Tainacan\Metadatum_Types\Compound' && $this->is_multiple() ) {
|
||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
||||
$children = $Tainacan_Metadata->fetch(
|
||||
[
|
||||
'parent' => $this->get_id(),
|
||||
'field_type' => 'Tainacan\Field_Types\Category',
|
||||
'metadatum_type' => 'Tainacan\Metadatum_Types\Category',
|
||||
'post_status' => 'any'
|
||||
]
|
||||
, 'OBJECT');
|
||||
|
@ -443,7 +453,7 @@ class Field extends Entity {
|
|||
}
|
||||
}
|
||||
|
||||
$fto = $this->get_field_type_object();
|
||||
$fto = $this->get_metadatum_type_object();
|
||||
|
||||
if (is_object($fto)) {
|
||||
$is_valid = $fto->validate_options($this);
|
||||
|
@ -456,10 +466,10 @@ class Field extends Entity {
|
|||
}
|
||||
|
||||
if (!is_array($is_valid)) {
|
||||
throw new \Exception( "Return of validate_options field type method should be an Array in case of error" );
|
||||
throw new \Exception( "Return of validate_options metadatum type method should be an Array in case of error" );
|
||||
}
|
||||
|
||||
$this->add_error('field_type_options', $is_valid);
|
||||
$this->add_error('metadatum_type_options', $is_valid);
|
||||
|
||||
return false;
|
||||
|
|
@ -48,21 +48,21 @@
|
|||
export default {
|
||||
created(){
|
||||
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id;
|
||||
this.field = ( this.field_id ) ? this.field_id : this.filter.field.field_id;
|
||||
this.metadatum = ( this.metadatum_id ) ? this.metadatum_id : this.filter.metadatum.metadatum_id;
|
||||
const vm = this;
|
||||
|
||||
let in_route = '/collection/' + this.collection + '/fields/' + this.field;
|
||||
let in_route = '/collection/' + this.collection + '/metadata/' + this.metadatum;
|
||||
|
||||
if(this.isRepositoryLevel){
|
||||
in_route = '/fields/'+ this.field;
|
||||
if(this.isRepositoryLevel || this.collection == 'filter_in_repository'){
|
||||
in_route = '/metadata/'+ this.metadatum;
|
||||
}
|
||||
|
||||
axios.get(in_route)
|
||||
.then( res => {
|
||||
let result = res.data;
|
||||
if( result && result.field_type ){
|
||||
vm.field_object = result;
|
||||
vm.type = result.field_type;
|
||||
if( result && result.metadatum_type ){
|
||||
vm.metadatum_object = result;
|
||||
vm.type = result.metadatum_type;
|
||||
vm.selectedValues();
|
||||
}
|
||||
})
|
||||
|
@ -78,7 +78,7 @@
|
|||
isLoading: false,
|
||||
type: '',
|
||||
collection: '',
|
||||
field: '',
|
||||
metadatum: '',
|
||||
label: ''
|
||||
}
|
||||
},
|
||||
|
@ -97,7 +97,7 @@
|
|||
onSelect(){
|
||||
this.$emit('input', {
|
||||
filter: 'autocomplete',
|
||||
field_id: this.field,
|
||||
metadatum_id: this.metadatum,
|
||||
collection_id: this.collection,
|
||||
value: this.results
|
||||
});
|
||||
|
@ -105,13 +105,13 @@
|
|||
search( query ){
|
||||
let promise = null;
|
||||
this.options = [];
|
||||
if ( this.type === 'Tainacan\\Field_Types\\Relationship' ) {
|
||||
let collectionTarget = ( this.field_object && this.field_object.field_type_options.collection_id ) ?
|
||||
this.field_object.field_type_options.collection_id : this.collection_id;
|
||||
if ( this.type === 'Tainacan\\Metadatum_Types\\Relationship' ) {
|
||||
let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadatum_type_options.collection_id ) ?
|
||||
this.metadatum_object.metadatum_type_options.collection_id : this.collection_id;
|
||||
promise = this.getValuesRelationship( collectionTarget );
|
||||
|
||||
} else {
|
||||
promise = this.getValuesPlainText( this.field, query, this.isRepositoryLevel );
|
||||
promise = this.getValuesPlainText( this.metadatum, query, this.isRepositoryLevel );
|
||||
}
|
||||
|
||||
promise.then( () => {
|
||||
|
@ -126,14 +126,14 @@
|
|||
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
|
||||
return false;
|
||||
|
||||
let index = this.query.metaquery.findIndex(newField => newField.key === this.field );
|
||||
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key === this.metadatum );
|
||||
if ( index >= 0){
|
||||
let metadata = this.query.metaquery[ index ];
|
||||
let collectionTarget = ( this.field_object && this.field_object.field_type_options.collection_id ) ?
|
||||
this.field_object.field_type_options.collection_id : this.collection_id;
|
||||
let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadatum_type_options.collection_id ) ?
|
||||
this.metadatum_object.metadatum_type_options.collection_id : this.collection_id;
|
||||
|
||||
|
||||
if ( this.type === 'Tainacan\\Field_Types\\Relationship' ) {
|
||||
if ( this.type === 'Tainacan\\Metadatum_Types\\Relationship' ) {
|
||||
let query = qs.stringify({ postin: metadata.value });
|
||||
|
||||
axios.get('/collection/' + collectionTarget + '/items?' + query)
|
||||
|
@ -161,7 +161,7 @@
|
|||
this.selected = '';
|
||||
this.$emit('input', {
|
||||
filter: 'autocomplete',
|
||||
field_id: this.field,
|
||||
metadatum_id: this.metadatum,
|
||||
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
|
||||
value: ''
|
||||
});
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace Tainacan\Filter_Types;
|
|||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Class TainacanFieldType
|
||||
* Class TainacanMetadatumType
|
||||
*/
|
||||
class Autocomplete extends Filter_Type {
|
||||
|
||||
|
@ -21,7 +21,7 @@ class Autocomplete extends Filter_Type {
|
|||
public function render( $filter ){
|
||||
return '<tainacan-filter-autocomplete name="'.$filter->get_name().'"
|
||||
collection_id="'.$filter->get_collection_id().'"
|
||||
filter_type="'.$filter->get_field()->get_field_type().'"
|
||||
field_id="'.$filter->get_field()->get_id().'"></tainacan-filter-autocomplete>';
|
||||
filter_type="'.$filter->get_metadatum()->get_metadatum_type().'"
|
||||
metadatum_id="'.$filter->get_metadatum()->get_id().'"></tainacan-filter-autocomplete>';
|
||||
}
|
||||
}
|
|
@ -20,8 +20,8 @@
|
|||
export default {
|
||||
created(){
|
||||
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id;
|
||||
this.field = ( this.field_id ) ? this.field_id : this.filter.field.field_id ;
|
||||
this.type = ( this.filter_type ) ? this.filter_type : this.filter.field.field_type;
|
||||
this.metadatum = ( this.metadatum_id ) ? this.metadatum_id : this.filter.metadatum.metadatum_id ;
|
||||
this.type = ( this.filter_type ) ? this.filter_type : this.filter.metadatum.metadatum_type;
|
||||
this.loadOptions();
|
||||
},
|
||||
data(){
|
||||
|
@ -30,21 +30,21 @@
|
|||
options: [],
|
||||
type: '',
|
||||
collection: '',
|
||||
field: '',
|
||||
metadatum: '',
|
||||
selected: [],
|
||||
taxonomy: ''
|
||||
}
|
||||
},
|
||||
props: {
|
||||
filter: {
|
||||
type: Object // concentrate all attributes field id and type
|
||||
type: Object // concentrate all attributes metadatum id and type
|
||||
},
|
||||
field_id: [Number], // not required, but overrides the filter field id if is set
|
||||
collection_id: [Number], // not required, but overrides the filter field id if is set
|
||||
filter_type: [String], // not required, but overrides the filter field type if is set
|
||||
metadatum_id: [Number], // not required, but overrides the filter metadatum id if is set
|
||||
collection_id: [Number], // not required, but overrides the filter metadatum id if is set
|
||||
filter_type: [String], // not required, but overrides the filter metadatum type if is set
|
||||
id: '',
|
||||
query: {
|
||||
type: Object // concentrate all attributes field id and type
|
||||
type: Object // concentrate all attributes metadatum id and type
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
@ -69,10 +69,10 @@
|
|||
let promise = null;
|
||||
this.isLoading = true;
|
||||
|
||||
axios.get('/collection/'+ this.collection +'/fields/' + this.field)
|
||||
axios.get('/collection/'+ this.collection +'/metadata/' + this.metadatum)
|
||||
.then( res => {
|
||||
let field = res.data;
|
||||
promise = this.getValuesCategory( field.field_type_options.taxonomy_id );
|
||||
let metadatum = res.data;
|
||||
promise = this.getValuesCategory( metadatum.metadatum_type_options.taxonomy_id );
|
||||
|
||||
promise.then( () => {
|
||||
this.isLoading = false;
|
||||
|
@ -106,7 +106,7 @@
|
|||
if ( !this.query || !this.query.taxquery || !Array.isArray( this.query.taxquery ) )
|
||||
return false;
|
||||
|
||||
let index = this.query.taxquery.findIndex(newField => newField.taxonomy === this.taxonomy );
|
||||
let index = this.query.taxquery.findIndex(newMetadatum => newMetadatum.taxonomy === this.taxonomy );
|
||||
if ( index >= 0){
|
||||
let metadata = this.query.taxquery[ index ];
|
||||
this.selected = metadata.terms;
|
||||
|
@ -119,7 +119,7 @@
|
|||
filter: 'selectbox',
|
||||
taxonomy: this.taxonomy,
|
||||
compare: 'IN',
|
||||
field_id: this.field,
|
||||
metadatum_id: this.metadatum,
|
||||
collection_id: this.collection,
|
||||
terms: this.selected
|
||||
});
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
export default {
|
||||
created(){
|
||||
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id;
|
||||
this.field = ( this.field_id ) ? this.field_id : this.filter.field.field_id ;
|
||||
this.type = ( this.filter_type ) ? this.filter_type : this.filter.field.field_type;
|
||||
this.metadatum = ( this.metadatum_id ) ? this.metadatum_id : this.filter.metadatum.metadatum_id ;
|
||||
this.type = ( this.filter_type ) ? this.filter_type : this.filter.metadatum.metadatum_type;
|
||||
this.loadOptions();
|
||||
},
|
||||
data(){
|
||||
|
@ -32,21 +32,21 @@
|
|||
isLoading: false,
|
||||
options: [],
|
||||
collection: '',
|
||||
field: '',
|
||||
metadatum: '',
|
||||
selected: '',
|
||||
taxonomy: ''
|
||||
}
|
||||
},
|
||||
props: {
|
||||
filter: {
|
||||
type: Object // concentrate all attributes field id and type
|
||||
type: Object // concentrate all attributes metadatum id and type
|
||||
},
|
||||
field_id: [Number], // not required, but overrides the filter field id if is set
|
||||
collection_id: [Number], // not required, but overrides the filter field id if is set
|
||||
filter_type: [String], // not required, but overrides the filter field type if is set
|
||||
metadatum_id: [Number], // not required, but overrides the filter metadatum id if is set
|
||||
collection_id: [Number], // not required, but overrides the filter metadatum id if is set
|
||||
filter_type: [String], // not required, but overrides the filter metadatum type if is set
|
||||
id: '',
|
||||
query: {
|
||||
type: Object // concentrate all attributes field id and type
|
||||
type: Object // concentrate all attributes metadatum id and type
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
@ -71,10 +71,10 @@
|
|||
let promise = null;
|
||||
this.isLoading = true;
|
||||
|
||||
axios.get('/collection/'+ this.collection +'/fields/' + this.field)
|
||||
axios.get('/collection/'+ this.collection +'/metadata/' + this.metadatum)
|
||||
.then( res => {
|
||||
let field = res.data;
|
||||
promise = this.getValuesCategory( field.field_type_options.taxonomy_id );
|
||||
let metadatum = res.data;
|
||||
promise = this.getValuesCategory( metadatum.metadatum_type_options.taxonomy_id );
|
||||
|
||||
promise.then( () => {
|
||||
this.isLoading = false;
|
||||
|
@ -108,7 +108,7 @@
|
|||
if ( !this.query || !this.query.taxquery || !Array.isArray( this.query.taxquery ) )
|
||||
return false;
|
||||
|
||||
let index = this.query.taxquery.findIndex(newField => newField.taxonomy === this.taxonomy );
|
||||
let index = this.query.taxquery.findIndex(newMetadatum => newMetadatum.taxonomy === this.taxonomy );
|
||||
if ( index >= 0){
|
||||
let metadata = this.query.taxquery[ index ];
|
||||
this.selected = metadata.terms;
|
||||
|
@ -121,7 +121,7 @@
|
|||
filter: 'selectbox',
|
||||
compare: 'IN',
|
||||
taxonomy: this.taxonomy,
|
||||
field_id: this.field,
|
||||
metadatum_id: this.metadatum,
|
||||
collection_id: this.collection,
|
||||
terms: this.selected
|
||||
});
|
||||
|
|
|
@ -19,19 +19,19 @@
|
|||
export default {
|
||||
created(){
|
||||
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id;
|
||||
this.field = ( this.field_id ) ? this.field_id : this.filter.field.field_id ;
|
||||
this.type = ( this.filter_type ) ? this.filter_type : this.filter.field.field_type;
|
||||
this.metadatum = ( this.metadatum_id ) ? this.metadatum_id : this.filter.metadatum.metadatum_id ;
|
||||
this.type = ( this.filter_type ) ? this.filter_type : this.filter.metadatum.metadatum_type;
|
||||
|
||||
let in_route = '/collection/' + this.collection + '/fields/' + this.field;
|
||||
let in_route = '/collection/' + this.collection + '/metadata/' + this.metadatum;
|
||||
|
||||
if(this.isRepositoryLevel){
|
||||
in_route = '/fields/' + this.field;
|
||||
if(this.isRepositoryLevel || this.collection == 'filter_in_repository'){
|
||||
in_route = '/metadata/'+ this.metadatum;
|
||||
}
|
||||
|
||||
axios.get(in_route)
|
||||
.then( res => {
|
||||
let field = res.data;
|
||||
this.selectedValues( field.field_type_options.taxonomy_id );
|
||||
let metadatum = res.data;
|
||||
this.selectedValues( metadatum.metadatum_type_options.taxonomy_id );
|
||||
});
|
||||
},
|
||||
data(){
|
||||
|
@ -42,20 +42,20 @@
|
|||
isLoading: false,
|
||||
type: '',
|
||||
collection: '',
|
||||
field: '',
|
||||
metadatum: '',
|
||||
taxonomy: ''
|
||||
}
|
||||
},
|
||||
props: {
|
||||
filter: {
|
||||
type: Object // concentrate all attributes field id and type
|
||||
type: Object // concentrate all attributes metadatum id and type
|
||||
},
|
||||
field_id: [Number], // not required, but overrides the filter field id if is set
|
||||
collection_id: [Number], // not required, but overrides the filter field id if is set
|
||||
filter_type: [String], // not required, but overrides the filter field type if is set
|
||||
metadatum_id: [Number], // not required, but overrides the filter metadatum id if is set
|
||||
collection_id: [Number], // not required, but overrides the filter metadatum id if is set
|
||||
filter_type: [String], // not required, but overrides the filter metadatum type if is set
|
||||
id: '',
|
||||
query: {
|
||||
type: Object // concentrate all attributes field id and type
|
||||
type: Object // concentrate all attributes metadatum id and type
|
||||
},
|
||||
isRepositoryLevel: Boolean,
|
||||
},
|
||||
|
@ -72,7 +72,7 @@
|
|||
filter: 'taginput',
|
||||
compare: 'IN',
|
||||
taxonomy: this.taxonomy,
|
||||
field_id: ( this.field_id ) ? this.field_id : this.filter.field,
|
||||
metadatum_id: ( this.metadatum_id ) ? this.metadatum_id : this.filter.metadatum,
|
||||
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
|
||||
terms: values
|
||||
});
|
||||
|
@ -83,12 +83,12 @@
|
|||
let promise = null;
|
||||
this.options = [];
|
||||
const q = query;
|
||||
const endpoint = this.isRepositoryLevel ? '/fields/' + this.field : '/collection/'+ this.collection +'/fields/' + this.field;
|
||||
const endpoint = this.isRepositoryLevel ? '/metadata/' + this.metadatum : '/collection/'+ this.collection +'/metadata/' + this.metadatum;
|
||||
|
||||
axios.get(endpoint)
|
||||
.then( res => {
|
||||
let field = res.data;
|
||||
promise = this.getValuesCategory( field.field_type_options.taxonomy_id, q );
|
||||
let metadatum = res.data;
|
||||
promise = this.getValuesCategory( metadatum.metadatum_type_options.taxonomy_id, q );
|
||||
this.isLoading = true;
|
||||
promise.then( () => {
|
||||
this.isLoading = false;
|
||||
|
@ -119,7 +119,7 @@
|
|||
if ( !this.query || !this.query.taxquery || !Array.isArray( this.query.taxquery ) )
|
||||
return false;
|
||||
|
||||
let index = this.query.taxquery.findIndex(newField => newField.taxonomy === this.taxonomy );
|
||||
let index = this.query.taxquery.findIndex(newMetadatum => newMetadatum.taxonomy === this.taxonomy );
|
||||
if ( index >= 0){
|
||||
let metadata = this.query.taxquery[ index ];
|
||||
for ( let id of metadata.terms ){
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace Tainacan\Filter_Types;
|
|||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Class TainacanFieldType
|
||||
* Class TainacanMetadatumType
|
||||
*/
|
||||
class CategoryCheckbox extends Filter_Type {
|
||||
|
||||
|
@ -20,8 +20,8 @@ class CategoryCheckbox extends Filter_Type {
|
|||
|
||||
public function render( $filter ){
|
||||
return '<tainacan-filter-category-checkbox name="'.$filter->get_name().'"
|
||||
filter_type="'.$filter->get_field()->get_field_type().'"
|
||||
filter_type="'.$filter->get_metadatum()->get_metadatum_type().'"
|
||||
collection_id="'.$filter->get_collection_id().'"
|
||||
field_id="'.$filter->get_field()->get_id().'"></tainacan-filter-checkbox>';
|
||||
metadatum_id="'.$filter->get_metadatum()->get_id().'"></tainacan-filter-checkbox>';
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ namespace Tainacan\Filter_Types;
|
|||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Class TainacanFieldType
|
||||
* Class TainacanMetadatumType
|
||||
*/
|
||||
class CategorySelectbox extends Filter_Type {
|
||||
|
||||
|
@ -20,8 +20,8 @@ class CategorySelectbox extends Filter_Type {
|
|||
|
||||
public function render( $filter ){
|
||||
return '<tainacan-filter-category-selectbox name="'.$filter->get_name().'"
|
||||
filter_type="'.$filter->get_field()->get_field_type().'"
|
||||
filter_type="'.$filter->get_metadatum()->get_metadatum_type().'"
|
||||
collection_id="'.$filter->get_collection_id().'"
|
||||
field_id="'.$filter->get_field()->get_id().'"></tainacan-filter-selectbox>';
|
||||
metadatum_id="'.$filter->get_metadatum()->get_id().'"></tainacan-filter-selectbox>';
|
||||
}
|
||||
}
|
|
@ -20,8 +20,8 @@ class CategoryTaginput extends Filter_Type {
|
|||
|
||||
public function render( $filter ){
|
||||
return '<tainacan-filter-category-taginput name="'.$filter->get_name().'"
|
||||
filter_type="'.$filter->get_field()->get_field_type().'"
|
||||
filter_type="'.$filter->get_metadatum()->get_metadatum_type().'"
|
||||
collection_id="'.$filter->get_collection_id().'"
|
||||
field_id="'.$filter->get_field()->get_id().'"></tainacan-filter-taginput>';
|
||||
metadatum_id="'.$filter->get_metadatum()->get_id().'"></tainacan-filter-taginput>';
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
<div
|
||||
v-for="(option, index) in options"
|
||||
:key="index"
|
||||
class="field">
|
||||
class="metadatum">
|
||||
<b-checkbox
|
||||
v-model="selected"
|
||||
:native-value="option.value"
|
||||
|
@ -19,21 +19,21 @@
|
|||
export default {
|
||||
created(){
|
||||
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id;
|
||||
this.field = ( this.field_id ) ? this.field_id : this.filter.field.field_id;
|
||||
this.metadatum = ( this.metadatum_id ) ? this.metadatum_id : this.filter.metadatum.metadatum_id;
|
||||
const vm = this;
|
||||
|
||||
let in_route = '/collection/' + this.collection + '/fields/' + this.field +'?nopaging=1';
|
||||
let in_route = '/collection/' + this.collection + '/metadata/' + this.metadatum +'?nopaging=1';
|
||||
|
||||
if(this.isRepositoryLevel){
|
||||
in_route = '/fields?nopaging=1';
|
||||
if(this.isRepositoryLevel || this.collection == 'filter_in_repository'){
|
||||
in_route = '/metadata?nopaging=1';
|
||||
}
|
||||
|
||||
axios.get(in_route)
|
||||
.then( res => {
|
||||
let result = res.data;
|
||||
if( result && result.field_type ){
|
||||
vm.field_object = result;
|
||||
vm.type = result.field_type;
|
||||
if( result && result.metadatum_type ){
|
||||
vm.metadatum_object = result;
|
||||
vm.type = result.metadatum_type;
|
||||
vm.loadOptions();
|
||||
}
|
||||
})
|
||||
|
@ -50,9 +50,9 @@
|
|||
options: [],
|
||||
type: '',
|
||||
collection: '',
|
||||
field: '',
|
||||
metadatum: '',
|
||||
selected: [],
|
||||
field_object: {}
|
||||
metadatum_object: {}
|
||||
}
|
||||
},
|
||||
mixins: [filter_type_mixin],
|
||||
|
@ -67,13 +67,13 @@
|
|||
let promise = null;
|
||||
this.isLoading = true;
|
||||
|
||||
if ( this.type === 'Tainacan\\Field_Types\\Relationship' ) {
|
||||
let collectionTarget = ( this.field_object && this.field_object.field_type_options.collection_id ) ?
|
||||
this.field_object.field_type_options.collection_id : this.collection_id;
|
||||
if ( this.type === 'Tainacan\\Metadatum_Types\\Relationship' ) {
|
||||
let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadatum_type_options.collection_id ) ?
|
||||
this.metadatum_object.metadatum_type_options.collection_id : this.collection_id;
|
||||
promise = this.getValuesRelationship( collectionTarget );
|
||||
|
||||
} else {
|
||||
promise = this.getValuesPlainText( this.field, null, this.isRepositoryLevel );
|
||||
promise = this.getValuesPlainText( this.metadatum, null, this.isRepositoryLevel );
|
||||
}
|
||||
|
||||
promise.then(() => {
|
||||
|
@ -89,7 +89,7 @@
|
|||
this.$emit('input', {
|
||||
filter: 'checkbox',
|
||||
compare: 'IN',
|
||||
field_id: this.field,
|
||||
metadatum_id: this.metadatum,
|
||||
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
|
||||
value: this.selected
|
||||
});
|
||||
|
@ -98,7 +98,7 @@
|
|||
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
|
||||
return false;
|
||||
|
||||
let index = this.query.metaquery.findIndex(newField => newField.key === this.field );
|
||||
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key === this.metadatum );
|
||||
if ( index >= 0){
|
||||
let metadata = this.query.metaquery[ index ];
|
||||
this.selected = metadata.value;
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace Tainacan\Filter_Types;
|
|||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Class TainacanFieldType
|
||||
* Class TainacanMetadatumType
|
||||
*/
|
||||
class Checkbox extends Filter_Type {
|
||||
|
||||
|
@ -20,8 +20,8 @@ class Checkbox extends Filter_Type {
|
|||
|
||||
public function render( $filter ){
|
||||
return '<tainacan-filter-checkbox name="'.$filter->get_name().'"
|
||||
filter_type="'.$filter->get_field()->get_field_type().'"
|
||||
filter_type="'.$filter->get_metadatum()->get_metadatum_type().'"
|
||||
collection_id="'.$filter->get_collection_id().'"
|
||||
field_id="'.$filter->get_field()->get_id().'"></tainacan-filter-selectbox>';
|
||||
metadatum_id="'.$filter->get_metadatum()->get_id().'"></tainacan-filter-selectbox>';
|
||||
}
|
||||
}
|
|
@ -64,20 +64,20 @@
|
|||
created(){
|
||||
const vm = this;
|
||||
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id;
|
||||
this.field = ( this.field_id ) ? this.field_id : this.filter.field.field_id;
|
||||
this.metadatum = ( this.metadatum_id ) ? this.metadatum_id : this.filter.metadatum.metadatum_id;
|
||||
|
||||
let in_route = '/collection/' + this.collection + '/fields/' + this.field;
|
||||
let in_route = '/collection/' + this.collection + '/metadata/' + this.metadatum;
|
||||
|
||||
if(this.isRepositoryLevel){
|
||||
in_route = '/fields/'+ this.field;
|
||||
if(this.isRepositoryLevel || this.collection == 'filter_in_repository'){
|
||||
in_route = '/metadata/'+ this.metadatum;
|
||||
}
|
||||
|
||||
axios.get(in_route)
|
||||
.then( res => {
|
||||
let result = res.data;
|
||||
if( result && result.field_type ){
|
||||
vm.field_object = result;
|
||||
vm.type = ( result.field_type === 'Tainacan\\Field_Types\\Date') ? 'date' : 'numeric';
|
||||
if( result && result.metadatum_type ){
|
||||
vm.metadatum_object = result;
|
||||
vm.type = ( result.metadatum_type === 'Tainacan\\Metadatum_Types\\Date') ? 'date' : 'numeric';
|
||||
vm.selectedValues();
|
||||
}
|
||||
})
|
||||
|
@ -96,16 +96,16 @@
|
|||
clear: false,
|
||||
type: 'numeric',
|
||||
collection: '',
|
||||
field: '',
|
||||
field_object: {},
|
||||
metadatum: '',
|
||||
metadatum_object: {},
|
||||
}
|
||||
},
|
||||
props: {
|
||||
filter: {
|
||||
type: Object // concentrate all attributes field id and type
|
||||
type: Object // concentrate all attributes metadatum id and type
|
||||
},
|
||||
field_id: [Number], // not required, but overrides the filter field id if is set
|
||||
collection_id: [Number], // not required, but overrides the filter field id if is set
|
||||
metadatum_id: [Number], // not required, but overrides the filter metadatum id if is set
|
||||
collection_id: [Number], // not required, but overrides the filter metadatum id if is set
|
||||
id: '',
|
||||
query: Object,
|
||||
isRepositoryLevel: Boolean,
|
||||
|
@ -165,7 +165,7 @@
|
|||
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
|
||||
return false;
|
||||
|
||||
let index = this.query.metaquery.findIndex(newField => newField.key === this.field );
|
||||
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key === this.metadatum );
|
||||
if ( index >= 0){
|
||||
let metadata = this.query.metaquery[ index ];
|
||||
if( metadata.value.length > 0 && this.type === 'numeric'){
|
||||
|
@ -204,7 +204,7 @@
|
|||
this.$emit('input', {
|
||||
filter: 'range',
|
||||
compare: 'BETWEEN',
|
||||
field_id: this.field,
|
||||
metadatum_id: this.metadatum,
|
||||
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
|
||||
value: ''
|
||||
});
|
||||
|
@ -278,7 +278,7 @@
|
|||
filter: 'range',
|
||||
type: type,
|
||||
compare: 'BETWEEN',
|
||||
field_id: vm.field,
|
||||
metadatum_id: vm.metadatum,
|
||||
collection_id: ( vm.collection_id ) ? vm.collection_id : vm.filter.collection_id,
|
||||
value: values
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace Tainacan\Filter_Types;
|
|||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Class TainacanFieldType
|
||||
* Class TainacanMetadatumType
|
||||
*/
|
||||
class Custom_Interval extends Filter_Type {
|
||||
|
||||
|
@ -17,14 +17,14 @@ class Custom_Interval extends Filter_Type {
|
|||
/**
|
||||
* @param $filter
|
||||
* @return string
|
||||
* @internal param $field
|
||||
* @internal param $metadatum
|
||||
*/
|
||||
public function render( $filter ){
|
||||
$type = ( $filter->get_field()->get_field_type() === 'Tainacan\Field_Types\Date' ) ? 'date' : 'numeric';
|
||||
$type = ( $filter->get_metadatum()->get_metadatum_type() === 'Tainacan\Metadatum_Types\Date' ) ? 'date' : 'numeric';
|
||||
return '<tainacan-filter-custom-interval
|
||||
name="'.$filter->get_name().'"
|
||||
typeRange="'.$type.'"
|
||||
collection_id="'.$filter->get_collection_id().'"
|
||||
field_id="'.$filter->get_field()->get_id().'"></tainacan-filter-custom-interval>';
|
||||
metadatum_id="'.$filter->get_metadatum()->get_id().'"></tainacan-filter-custom-interval>';
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Filter_Types;
|
||||
use Tainacan\Field_Types;
|
||||
use Tainacan\Metadatum_Types;
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
|
@ -15,10 +15,10 @@ abstract class Filter_Type {
|
|||
add_action('register_filter_types', array(&$this, 'register_filter_type'));
|
||||
}
|
||||
|
||||
abstract function render( $field );
|
||||
abstract function render( $metadatum );
|
||||
|
||||
/**
|
||||
* generate the fields for this field type
|
||||
* generate the metadata for this metadatum type
|
||||
*/
|
||||
public function form(){
|
||||
|
||||
|
@ -72,19 +72,19 @@ abstract class Filter_Type {
|
|||
*
|
||||
* This method should be declared by each filter type sub classes
|
||||
*
|
||||
* @param \Tainacan\Entities\Filter $filter The field object that is beeing validated
|
||||
* @param \Tainacan\Entities\Filter $filter The metadatum object that is beeing validated
|
||||
*
|
||||
* @return true|array True if options are valid. If invalid, returns an array where keys are the field keys and values are error messages.
|
||||
* @return true|array True if options are valid. If invalid, returns an array where keys are the metadatum keys and values are error messages.
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function validate_options(\Tainacan\Entities\Filter $filter) {
|
||||
$field_type = $filter->get_field()->get_field_type();
|
||||
//if there is no field to validate
|
||||
if( !$field_type ){
|
||||
$metadatum_type = $filter->get_metadatum()->get_metadatum_type();
|
||||
//if there is no metadatum to validate
|
||||
if( !$metadatum_type ){
|
||||
return true;
|
||||
}
|
||||
|
||||
$class = ( is_object( $field_type ) ) ? $field_type : new $field_type();
|
||||
$class = ( is_object( $metadatum_type ) ) ? $metadatum_type : new $metadatum_type();
|
||||
|
||||
if(in_array( $class->get_primitive_type(), $this->supported_types )){
|
||||
return true;
|
||||
|
|
|
@ -3,21 +3,21 @@ import { tainacan as axios } from '../../js/axios/axios';
|
|||
export const filter_type_mixin = {
|
||||
props: {
|
||||
filter: {
|
||||
type: Object // concentrate all attributes field id and type
|
||||
type: Object // concentrate all attributes metadatum id and type
|
||||
},
|
||||
field_id: [Number], // not required, but overrides the filter field id if is set
|
||||
collection_id: [Number], // not required, but overrides the filter field id if is set
|
||||
filter_type: [String], // not required, but overrides the filter field type if is set
|
||||
metadatum_id: [Number], // not required, but overrides the filter metadatum id if is set
|
||||
collection_id: [Number], // not required, but overrides the filter metadatum id if is set
|
||||
filter_type: [String], // not required, but overrides the filter metadatum type if is set
|
||||
id: '',
|
||||
query: {}
|
||||
},
|
||||
methods: {
|
||||
getValuesPlainText(fieldId, search, isRepositoryLevel) {
|
||||
getValuesPlainText(metadatumId, search, isRepositoryLevel) {
|
||||
|
||||
let url = '/collection/' + this.collection + '/fields/' + fieldId + '?fetch=all_field_values&nopaging=1';
|
||||
let url = '/collection/' + this.collection + '/metadata/' + metadatumId + '?fetch=all_metadatum_values&nopaging=1';
|
||||
|
||||
if(isRepositoryLevel){
|
||||
url = '/fields/' + fieldId + '?fetch=all_field_values&nopaging=1';
|
||||
url = '/metadata/' + metadatumId + '?fetch=all_metadatum_values&nopaging=1';
|
||||
}
|
||||
|
||||
if( search ){
|
||||
|
|
|
@ -25,21 +25,21 @@
|
|||
export default {
|
||||
created(){
|
||||
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id;
|
||||
this.field = ( this.field_id ) ? this.field_id : this.filter.field.field_id;
|
||||
this.metadatum = ( this.metadatum_id ) ? this.metadatum_id : this.filter.metadatum.metadatum_id;
|
||||
const vm = this;
|
||||
|
||||
let in_route = '/collection/' + this.collection + '/fields/' + this.field;
|
||||
let in_route = '/collection/' + this.collection + '/metadata/' + this.metadatum;
|
||||
|
||||
if(this.isRepositoryLevel){
|
||||
in_route = '/fields/'+ this.field;
|
||||
if(this.isRepositoryLevel || this.collection == 'filter_in_repository'){
|
||||
in_route = '/metadata/'+ this.metadatum;
|
||||
}
|
||||
|
||||
axios.get(in_route)
|
||||
.then( res => {
|
||||
let result = res.data;
|
||||
if( result && result.field_type ){
|
||||
vm.field_object = result;
|
||||
vm.type = result.field_type;
|
||||
if( result && result.metadatum_type ){
|
||||
vm.metadatum_object = result;
|
||||
vm.type = result.metadatum_type;
|
||||
vm.loadOptions();
|
||||
}
|
||||
})
|
||||
|
@ -56,7 +56,7 @@
|
|||
options: [],
|
||||
type: '',
|
||||
collection: '',
|
||||
field: ''
|
||||
metadatum: ''
|
||||
}
|
||||
},
|
||||
mixins: [filter_type_mixin],
|
||||
|
@ -64,7 +64,7 @@
|
|||
selected() {
|
||||
if ( this.query && this.query.metaquery && Array.isArray( this.query.metaquery ) ) {
|
||||
|
||||
let index = this.query.metaquery.findIndex(newField => newField.key === this.field );
|
||||
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key === this.metadatum );
|
||||
if ( index >= 0){
|
||||
let metadata = this.query.metaquery[ index ];
|
||||
return metadata.value;
|
||||
|
@ -78,7 +78,7 @@
|
|||
this.isLoading = true;
|
||||
|
||||
let promise = null;
|
||||
promise = this.getValuesPlainText( this.field, null, this.isRepositoryLevel );
|
||||
promise = this.getValuesPlainText( this.metadatum, null, this.isRepositoryLevel );
|
||||
|
||||
promise.then(() => {
|
||||
this.isLoading = false;
|
||||
|
@ -91,7 +91,7 @@
|
|||
onSelect(value){
|
||||
this.$emit('input', {
|
||||
filter: 'selectbox',
|
||||
field_id: this.field,
|
||||
metadatum_id: this.metadatum,
|
||||
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
|
||||
value: ( value ) ? value : ''
|
||||
});
|
||||
|
@ -100,7 +100,7 @@
|
|||
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
|
||||
return false;
|
||||
|
||||
let index = this.query.metaquery.findIndex(newField => newField.key === this.field );
|
||||
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key === this.metadatum );
|
||||
if ( index >= 0){
|
||||
let metadata = this.query.metaquery[ index ];
|
||||
this.selected = metadata.value;
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace Tainacan\Filter_Types;
|
|||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Class TainacanFieldType
|
||||
* Class TainacanMetadatumType
|
||||
*/
|
||||
class Selectbox extends Filter_Type {
|
||||
|
||||
|
@ -20,8 +20,8 @@ class Selectbox extends Filter_Type {
|
|||
|
||||
public function render( $filter ){
|
||||
return '<tainacan-filter-selectbox name="'.$filter->get_name().'"
|
||||
filter_type="'.$filter->get_field()->get_field_type().'"
|
||||
filter_type="'.$filter->get_metadatum()->get_metadatum_type().'"
|
||||
collection_id="'.$filter->get_collection_id().'"
|
||||
field_id="'.$filter->get_field()->get_id().'"></tainacan-filter-selectbox>';
|
||||
metadatum_id="'.$filter->get_metadatum()->get_id().'"></tainacan-filter-selectbox>';
|
||||
}
|
||||
}
|
|
@ -21,21 +21,21 @@
|
|||
export default {
|
||||
created(){
|
||||
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id;
|
||||
this.field = ( this.field_id ) ? this.field_id : this.filter.field.field_id;
|
||||
this.metadatum = ( this.metadatum_id ) ? this.metadatum_id : this.filter.metadatum.metadatum_id;
|
||||
const vm = this;
|
||||
|
||||
let in_route = '/collection/' + this.collection + '/fields/' + this.field;
|
||||
let in_route = '/collection/' + this.collection + '/metadata/' + this.metadatum;
|
||||
|
||||
if(this.isRepositoryLevel){
|
||||
in_route = '/fields?nopaging=1';
|
||||
if(this.isRepositoryLevel || this.collection == 'filter_in_repository'){
|
||||
in_route = '/metadata?nopaging=1';
|
||||
}
|
||||
|
||||
axios.get(in_route)
|
||||
.then( res => {
|
||||
let result = res.data;
|
||||
if( result && result.field_type ){
|
||||
vm.field_object = result;
|
||||
vm.type = result.field_type;
|
||||
if( result && result.metadatum_type ){
|
||||
vm.metadatum_object = result;
|
||||
vm.type = result.metadatum_type;
|
||||
vm.selectedValues();
|
||||
}
|
||||
})
|
||||
|
@ -51,8 +51,8 @@
|
|||
isLoading: false,
|
||||
type: '',
|
||||
collection: '',
|
||||
field: '',
|
||||
field_object: {}
|
||||
metadatum: '',
|
||||
metadatum_object: {}
|
||||
}
|
||||
},
|
||||
props: {
|
||||
|
@ -71,7 +71,7 @@
|
|||
this.$emit('input', {
|
||||
filter: 'taginput',
|
||||
compare: 'IN',
|
||||
field_id: this.field,
|
||||
metadatum_id: this.metadatum,
|
||||
collection_id: this.collection,
|
||||
value: values
|
||||
});
|
||||
|
@ -81,13 +81,13 @@
|
|||
search( query ){
|
||||
let promise = null;
|
||||
this.options = [];
|
||||
if ( this.type === 'Tainacan\\Field_Types\\Relationship' ) {
|
||||
let collectionTarget = ( this.field_object && this.field_object.field_type_options.collection_id ) ?
|
||||
this.field_object.field_type_options.collection_id : this.collection_id;
|
||||
if ( this.type === 'Tainacan\\Metadatum_Types\\Relationship' ) {
|
||||
let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadatum_type_options.collection_id ) ?
|
||||
this.metadatum_object.metadatum_type_options.collection_id : this.collection_id;
|
||||
promise = this.getValuesRelationship( collectionTarget, query );
|
||||
|
||||
} else {
|
||||
promise = this.getValuesPlainText( this.field, query, this.isRepositoryLevel );
|
||||
promise = this.getValuesPlainText( this.metadatum, query, this.isRepositoryLevel );
|
||||
}
|
||||
this.isLoading = true;
|
||||
promise.then(() => {
|
||||
|
@ -102,14 +102,14 @@
|
|||
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
|
||||
return false;
|
||||
|
||||
let index = this.query.metaquery.findIndex(newField => newField.key === this.field );
|
||||
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key === this.metadatum );
|
||||
if ( index >= 0){
|
||||
let metadata = this.query.metaquery[ index ];
|
||||
let collectionTarget = ( this.field_object && this.field_object.field_type_options.collection_id ) ?
|
||||
this.field_object.field_type_options.collection_id : this.collection_id;
|
||||
let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadatum_type_options.collection_id ) ?
|
||||
this.metadatum_object.metadatum_type_options.collection_id : this.collection_id;
|
||||
|
||||
|
||||
if ( this.type === 'Tainacan\\Field_Types\\Relationship' ) {
|
||||
if ( this.type === 'Tainacan\\Metadatum_Types\\Relationship' ) {
|
||||
let query = qs.stringify({ postin: metadata.value });
|
||||
|
||||
axios.get('/collection/' + collectionTarget + '/items?' + query)
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace Tainacan\Filter_Types;
|
|||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Class TainacanFieldType
|
||||
* Class TainacanMetadatumType
|
||||
*/
|
||||
class Taginput extends Filter_Type {
|
||||
|
||||
|
@ -20,8 +20,8 @@ class Taginput extends Filter_Type {
|
|||
|
||||
public function render( $filter ){
|
||||
return '<tainacan-filter-taginput name="'.$filter->get_name().'"
|
||||
filter_type="'.$filter->get_field()->get_field_type().'"
|
||||
filter_type="'.$filter->get_metadatum()->get_metadatum_type().'"
|
||||
collection_id="'.$filter->get_collection_id().'"
|
||||
field_id="'.$filter->get_field()->get_id().'"></tainacan-filter-taginput>';
|
||||
metadatum_id="'.$filter->get_metadatum()->get_id().'"></tainacan-filter-taginput>';
|
||||
}
|
||||
}
|
|
@ -66,7 +66,7 @@
|
|||
'setPage'
|
||||
]),
|
||||
listen( event ){
|
||||
this.$eventBusSearch.$emit( 'input', ( event.field_id ) ? event : event.detail[0] );
|
||||
this.$eventBusSearch.$emit( 'input', ( event.metadatum_id ) ? event : event.detail[0] );
|
||||
},
|
||||
setFilterTypeMessage( message ){
|
||||
this.filterTypeMessage = message;
|
||||
|
|
|
@ -54,13 +54,13 @@
|
|||
name: '',
|
||||
parent: 0,
|
||||
showForm: false,
|
||||
field_id: this.field.field.id
|
||||
metadatum_id: this.metadatum.metadatum.id
|
||||
}
|
||||
},
|
||||
props: {
|
||||
id: String,
|
||||
item_id: [Number,String],
|
||||
field: [Number,String],
|
||||
metadatum: [Number,String],
|
||||
taxonomy_id: [Number,String],
|
||||
value:[ Array, Boolean, Number ],
|
||||
options: {
|
||||
|
@ -100,8 +100,8 @@
|
|||
let id = ( res.id ) ? res.id : res.data.id;
|
||||
let val = this.value;
|
||||
|
||||
if( !Array.isArray( val ) && this.field.field.multiple === 'no' ){
|
||||
axios.patch(`/item/${this.item_id}/metadata/${this.field_id}`, {
|
||||
if( !Array.isArray( val ) && this.metadatum.metadatum.multiple === 'no' ){
|
||||
axios.patch(`/item/${this.item_id}/metadata/${this.metadatum_id}`, {
|
||||
values: id,
|
||||
}).then(() => {
|
||||
instance.$emit('newTerm', id);
|
||||
|
@ -109,7 +109,7 @@
|
|||
} else {
|
||||
val = ( val ) ? val : [];
|
||||
val.push( id );
|
||||
axios.patch(`/item/${this.item_id}/metadata/${this.field_id}`, {
|
||||
axios.patch(`/item/${this.item_id}/metadata/${this.metadatum_id}`, {
|
||||
values: val,
|
||||
}).then( () => {
|
||||
instance.$emit('newTerm', val);
|
|
@ -10,8 +10,8 @@
|
|||
class="add-new-term"
|
||||
v-if="getComponent() !== 'tainacan-category-tag-input' && allowNew"
|
||||
:taxonomy_id="taxonomy"
|
||||
:field="field"
|
||||
:item_id="field.item.id"
|
||||
:metadatum="metadatum"
|
||||
:item_id="metadatum.item.id"
|
||||
:value="valueComponent"
|
||||
:options="getOptions(0)"
|
||||
@newTerm="reload"/>
|
||||
|
@ -27,15 +27,15 @@
|
|||
|
||||
export default {
|
||||
created(){
|
||||
let field_type_options = this.field.field.field_type_options;
|
||||
this.component = ( field_type_options && field_type_options.input_type )
|
||||
? this.field.field.field_type_options.input_type : this.componentAttribute
|
||||
let metadatum_type_options = this.metadatum.metadatum.metadatum_type_options;
|
||||
this.component = ( metadatum_type_options && metadatum_type_options.input_type )
|
||||
? this.metadatum.metadatum.metadatum_type_options.input_type : this.componentAttribute
|
||||
|
||||
this.collectionId = this.field.field.collection_id;
|
||||
this.taxonomy = field_type_options.taxonomy_id;
|
||||
this.collectionId = this.metadatum.metadatum.collection_id;
|
||||
this.taxonomy = metadatum_type_options.taxonomy_id;
|
||||
|
||||
if( field_type_options && field_type_options.allow_new_terms ){
|
||||
this.allowNew = field_type_options.allow_new_terms === 'yes'
|
||||
if( metadatum_type_options && metadatum_type_options.allow_new_terms ){
|
||||
this.allowNew = metadatum_type_options.allow_new_terms === 'yes'
|
||||
}
|
||||
this.getTermsFromTaxonomy();
|
||||
this.getTermsId();
|
||||
|
@ -65,7 +65,7 @@
|
|||
}
|
||||
},
|
||||
props: {
|
||||
field: {
|
||||
metadatum: {
|
||||
type: Object
|
||||
},
|
||||
componentAttribute: {
|
||||
|
@ -76,9 +76,9 @@
|
|||
},
|
||||
methods: {
|
||||
getComponent(){
|
||||
if( this.field.field
|
||||
&& this.field.field.field_type_options && this.field.field.field_type_options.input_type ){
|
||||
return this.field.field.field_type_options.input_type;
|
||||
if( this.metadatum.metadatum
|
||||
&& this.metadatum.metadatum.metadatum_type_options && this.metadatum.metadatum.metadatum_type_options.input_type ){
|
||||
return this.metadatum.metadatum.metadatum_type_options.input_type;
|
||||
}
|
||||
},
|
||||
getTermsFromTaxonomy(){
|
||||
|
@ -115,8 +115,8 @@
|
|||
}
|
||||
}
|
||||
|
||||
if( values.length > 0 && this.field.field){
|
||||
this.valueComponent = ( this.field.field && this.field.field.multiple === 'no' ) ? values[0] : values
|
||||
if( values.length > 0 && this.metadatum.metadatum){
|
||||
this.valueComponent = ( this.metadatum.metadatum && this.metadatum.metadatum.multiple === 'no' ) ? values[0] : values
|
||||
}
|
||||
|
||||
},
|
|
@ -38,8 +38,8 @@
|
|||
</label>
|
||||
<b-select
|
||||
v-if="listInputType"
|
||||
name="field_type_options[component_type]"
|
||||
placeholder="Select the input type for the category field"
|
||||
name="metadatum_type_options[component_type]"
|
||||
placeholder="Select the input type for the category metadatum"
|
||||
@input="emitValues()"
|
||||
v-model="input_type">
|
||||
<option
|
||||
|
@ -51,8 +51,8 @@
|
|||
</b-select>
|
||||
|
||||
<b-select
|
||||
name="field_type_options[input_type]"
|
||||
placeholder="Select the input type for the category field"
|
||||
name="metadatum_type_options[input_type]"
|
||||
placeholder="Select the input type for the category metadatum"
|
||||
v-model="input_type"
|
||||
@input="emitValues()"
|
||||
v-else>
|
||||
|
@ -96,7 +96,7 @@
|
|||
components: {BCheckbox},
|
||||
props: {
|
||||
value: [ String, Object, Array ],
|
||||
field: [ String, Object ],
|
||||
metadatum: [ String, Object ],
|
||||
errors: [ String, Object, Array ]
|
||||
},
|
||||
created(){
|
||||
|
@ -119,7 +119,7 @@
|
|||
},
|
||||
computed: {
|
||||
listInputType(){
|
||||
if( this.field && this.field.multiple === 'no' ){
|
||||
if( this.metadatum && this.metadatum.multiple === 'no' ){
|
||||
let types = Object.keys( this.single_types );
|
||||
let hasValue = this.value && this.value.input_type && types.indexOf( this.value.input_type ) >= 0;
|
||||
this.setInputType( ( hasValue ) ? this.value.input_type : 'tainacan-category-radio' );
|
|
@ -1,20 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Field_Types;
|
||||
namespace Tainacan\Metadatum_Types;
|
||||
|
||||
use Tainacan\Entities\Field;
|
||||
use Tainacan\Entities\Metadatum;
|
||||
use Tainacan\Entities\Item_Metadata_Entity;
|
||||
use Tainacan\Repositories\Fields;
|
||||
use Tainacan\Repositories\Metadata;
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Class TainacanFieldType
|
||||
* Class TainacanMetadatumType
|
||||
*/
|
||||
class Category extends Field_Type {
|
||||
class Category extends Metadatum_Type {
|
||||
|
||||
function __construct(){
|
||||
// call field type constructor
|
||||
// call metadatum type constructor
|
||||
parent::__construct();
|
||||
$this->set_primitive_type('term');
|
||||
|
||||
|
@ -55,36 +55,36 @@ class Category extends Field_Type {
|
|||
$options = ( isset( $this->get_options()['options'] ) ) ? $this->get_options()['options'] : '';
|
||||
return '<tainacan-selectbox
|
||||
options="' . $options . '"
|
||||
field_id ="'.$itemMetadata->get_field()->get_id().'"
|
||||
metadatum_id ="'.$itemMetadata->get_metadatum()->get_id().'"
|
||||
item_id="'.$itemMetadata->get_item()->get_id().'"
|
||||
value=\''.json_encode( $itemMetadata->get_value() ).'\'
|
||||
name="'.$itemMetadata->get_field()->get_name().'"></tainacan-selectbox>';
|
||||
name="'.$itemMetadata->get_metadatum()->get_name().'"></tainacan-selectbox>';
|
||||
}
|
||||
|
||||
public function validate_options( Field $field) {
|
||||
public function validate_options( Metadatum $metadatum) {
|
||||
|
||||
if ( !in_array($field->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) )
|
||||
if ( !in_array($metadatum->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) )
|
||||
return true;
|
||||
|
||||
if (empty($this->get_option('taxonomy_id')))
|
||||
return ['taxonomy_id' => __('Please select a taxonomy', 'tainacan')];
|
||||
|
||||
$Tainacan_Fields = Fields::get_instance();
|
||||
$Tainacan_Metadata = Metadata::get_instance();
|
||||
|
||||
$category_fields = $Tainacan_Fields->fetch([
|
||||
'collection_id' => $field->get_collection_id(),
|
||||
'field_type' => 'Tainacan\\Field_Types\\Category'
|
||||
$category_metadata = $Tainacan_Metadata->fetch([
|
||||
'collection_id' => $metadatum->get_collection_id(),
|
||||
'metadatum_type' => 'Tainacan\\Metadatum_Types\\Category'
|
||||
], 'OBJECT');
|
||||
|
||||
$category_fields = array_map(function ($field_map) {
|
||||
$fto = $field_map->get_field_type_object();
|
||||
return [ $field_map->get_id() => $fto->get_option('taxonomy_id') ];
|
||||
}, $category_fields);
|
||||
$category_metadata = array_map(function ($metadatum_map) {
|
||||
$fto = $metadatum_map->get_metadatum_type_object();
|
||||
return [ $metadatum_map->get_id() => $fto->get_option('taxonomy_id') ];
|
||||
}, $category_metadata);
|
||||
|
||||
if( is_array( $category_fields ) ){
|
||||
foreach ($category_fields as $field_id => $category_field) {
|
||||
if ( is_array( $category_field ) && key($category_field) != $field->get_id()
|
||||
&& in_array($this->get_option('taxonomy_id'), $category_field)) {
|
||||
if( is_array( $category_metadata ) ){
|
||||
foreach ($category_metadata as $metadatum_id => $category_metadatum) {
|
||||
if ( is_array( $category_metadatum ) && key($category_metadatum) != $metadatum->get_id()
|
||||
&& in_array($this->get_option('taxonomy_id'), $category_metadatum)) {
|
||||
return ['taxonomy_id' => __('You can not have 2 taxonomy metadata using the same taxonomy in a collection.', 'tainacan')];
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ class Category extends Field_Type {
|
|||
}
|
||||
|
||||
/**
|
||||
* Validate item based on field type categories options
|
||||
* Validate item based on metadatum type categories options
|
||||
*
|
||||
* @param Item_Metadata_Entity $item_metadata
|
||||
*
|
||||
|
@ -137,7 +137,7 @@ class Category extends Field_Type {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the value of an Item_Metadata_Entity using a field of this field type as an html string
|
||||
* Return the value of an Item_Metadata_Entity using a metadatum of this metadatum type as an html string
|
||||
* @param Item_Metadata_Entity $item_metadata
|
||||
* @return string The HTML representation of the value, containing one or multiple terms, separated by comma, linked to term page
|
||||
*/
|
|
@ -1,19 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Field_Types;
|
||||
namespace Tainacan\Metadatum_Types;
|
||||
|
||||
use Tainacan\Entities\Field;
|
||||
use Tainacan\Entities\Metadatum;
|
||||
use Tainacan\Entities\Item_Metadata_Entity;
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Class TainacanFieldType
|
||||
* Class TainacanMetadatumType
|
||||
*/
|
||||
class Compound extends Field_Type {
|
||||
class Compound extends Metadatum_Type {
|
||||
|
||||
function __construct(){
|
||||
// call field type constructor
|
||||
// call metadatum type constructor
|
||||
parent::__construct();
|
||||
$this->set_primitive_type('compound');
|
||||
$this->set_component('tainacan-compound');
|
||||
|
@ -27,14 +27,14 @@ class Compound extends Field_Type {
|
|||
public function render( $itemMetadata ){
|
||||
return '<tainacan-text
|
||||
id="tainacan-text-' . $itemMetadata->get_item()->WP_Post->post_name . '"
|
||||
field_id ="'.$itemMetadata->get_field()->get_id().'"
|
||||
metadatum_id ="'.$itemMetadata->get_metadatum()->get_id().'"
|
||||
item_id="'.$itemMetadata->get_item()->get_id().'"
|
||||
value=\''.json_encode( $itemMetadata->get_value() ).'\'
|
||||
name="'.$itemMetadata->get_field()->get_name().'"></tainacan-text>';
|
||||
name="'.$itemMetadata->get_metadatum()->get_name().'"></tainacan-text>';
|
||||
}
|
||||
|
||||
/**
|
||||
* generate the fields for this field type
|
||||
* generate the metadata for this metadatum type
|
||||
*/
|
||||
public function form(){
|
||||
|
||||
|
@ -42,9 +42,9 @@ class Compound extends Field_Type {
|
|||
|
||||
|
||||
/**
|
||||
* Return the value of an Item_Metadata_Entity using a field of this field type as an html string
|
||||
* Return the value of an Item_Metadata_Entity using a metadatum of this metadatum type as an html string
|
||||
* @param Item_Metadata_Entity $item_metadata
|
||||
* @return string The HTML representation of the value, each HTML representation of the value of each field composing this metadata
|
||||
* @return string The HTML representation of the value, each HTML representation of the value of each metadatum composing this metadata
|
||||
*/
|
||||
public function get_value_as_html(Item_Metadata_Entity $item_metadata) {
|
||||
|
||||
|
@ -58,11 +58,11 @@ class Compound extends Field_Type {
|
|||
|
||||
foreach ( $value as $compound_element ) {
|
||||
|
||||
$return .= '<div class="tainacan-compund-field">';
|
||||
$return .= '<div class="tainacan-compund-metadatum">';
|
||||
|
||||
foreach ( $compound_element as $meta ) {
|
||||
if ( $meta instanceof Item_Metadata_Entity ) {
|
||||
$return .= '<h4>' . $meta->get_field()->get_name() . "</h4>\n";
|
||||
$return .= '<h4>' . $meta->get_metadatum()->get_name() . "</h4>\n";
|
||||
$return .= '<p>' . $meta->get_value_as_html() . '</p>' . "\n\n";
|
||||
}
|
||||
}
|
||||
|
@ -78,10 +78,10 @@ class Compound extends Field_Type {
|
|||
|
||||
foreach ( $value as $meta ) {
|
||||
|
||||
$return .= '<div class="tainacan-compund-field">';
|
||||
$return .= '<div class="tainacan-compund-metadatum">';
|
||||
|
||||
if ( $meta instanceof Item_Metadata_Entity ) {
|
||||
$return .= '<h4>' . $meta->get_field()->get_name() . "</h4>\n";
|
||||
$return .= '<h4>' . $meta->get_metadatum()->get_name() . "</h4>\n";
|
||||
$return .= '<p>' . $meta->get_value_as_html() . '</p>';
|
||||
}
|
||||
|
|
@ -1,18 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Field_Types;
|
||||
namespace Tainacan\Metadatum_Types;
|
||||
|
||||
use Tainacan\Entities\Field;
|
||||
use Tainacan\Entities\Metadatum;
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Class TainacanFieldType
|
||||
* Class TainacanMetadatumType
|
||||
*/
|
||||
class Core_Description extends Field_Type {
|
||||
class Core_Description extends Metadatum_Type {
|
||||
|
||||
function __construct(){
|
||||
// call field type constructor
|
||||
// call metadatum type constructor
|
||||
parent::__construct();
|
||||
$this->set_primitive_type('string');
|
||||
$this->set_core(true);
|
||||
|
@ -28,21 +28,21 @@ class Core_Description extends Field_Type {
|
|||
public function render( $itemMetadata ){
|
||||
return '<tainacan-textarea
|
||||
id="tainacan-textarea-' . $itemMetadata->get_item()->WP_Post->post_name . '"
|
||||
field_id ="'.$itemMetadata->get_field()->get_id().'"
|
||||
metadatum_id ="'.$itemMetadata->get_metadatum()->get_id().'"
|
||||
item_id="'.$itemMetadata->get_item()->get_id().'"
|
||||
value=\''.json_encode( $itemMetadata->get_value() ).'\'
|
||||
name="'.$itemMetadata->get_field()->get_name().'"></tainacan-textarea>';
|
||||
name="'.$itemMetadata->get_metadatum()->get_name().'"></tainacan-textarea>';
|
||||
}
|
||||
|
||||
/**
|
||||
* generate the fields for this field type
|
||||
* generate the metadata for this metadatum type
|
||||
*/
|
||||
public function form(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Description core Field type is stored as the item content (description)
|
||||
* Description core Metadatum type is stored as the item content (description)
|
||||
*
|
||||
* Lets validate it as the item description
|
||||
*
|
||||
|
@ -67,12 +67,12 @@ class Core_Description extends Field_Type {
|
|||
|
||||
*/
|
||||
|
||||
public function validate_options( Field $field ) {
|
||||
public function validate_options( Metadatum $metadatum ) {
|
||||
|
||||
if ( !in_array($field->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) )
|
||||
if ( !in_array($metadatum->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) )
|
||||
return true;
|
||||
|
||||
if ( $field->get_multiple() != 'no') {
|
||||
if ( $metadatum->get_multiple() != 'no') {
|
||||
return ['multiple' => __('Core Metadata can not accept multiple values', 'tainacan')];
|
||||
}
|
||||
|
|
@ -1,19 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Field_Types;
|
||||
namespace Tainacan\Metadatum_Types;
|
||||
|
||||
use Tainacan\Entities\Field;
|
||||
use Tainacan\Entities\Metadatum;
|
||||
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Class TainacanFieldType
|
||||
* Class TainacanMetadatumType
|
||||
*/
|
||||
class Core_Title extends Field_Type {
|
||||
class Core_Title extends Metadatum_Type {
|
||||
|
||||
function __construct(){
|
||||
// call field type constructor
|
||||
// call metadatum type constructor
|
||||
parent::__construct();
|
||||
$this->set_primitive_type('string');
|
||||
$this->set_core(true);
|
||||
|
@ -29,21 +29,21 @@ class Core_Title extends Field_Type {
|
|||
public function render( $itemMetadata ){
|
||||
return '<tainacan-text
|
||||
id="tainacan-text-' . $itemMetadata->get_item()->WP_Post->post_name . '"
|
||||
field_id ="'.$itemMetadata->get_field()->get_id().'"
|
||||
metadatum_id ="'.$itemMetadata->get_metadatum()->get_id().'"
|
||||
item_id="'.$itemMetadata->get_item()->get_id().'"
|
||||
value=\''.json_encode( $itemMetadata->get_value() ).'\'
|
||||
name="'.$itemMetadata->get_field()->get_name().'"></tainacan-text>';
|
||||
name="'.$itemMetadata->get_metadatum()->get_name().'"></tainacan-text>';
|
||||
}
|
||||
|
||||
/**
|
||||
* generate the fields for this field type
|
||||
* generate the metadata for this metadatum type
|
||||
*/
|
||||
public function form(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Title core Field type is stored as the item title
|
||||
* Title core Metadatum type is stored as the item title
|
||||
*
|
||||
* Lets validate it as the item title
|
||||
*
|
||||
|
@ -67,12 +67,12 @@ class Core_Title extends Field_Type {
|
|||
}
|
||||
*/
|
||||
|
||||
public function validate_options( Field $field ) {
|
||||
public function validate_options( Metadatum $metadatum ) {
|
||||
|
||||
if ( !in_array($field->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) )
|
||||
if ( !in_array($metadatum->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) )
|
||||
return true;
|
||||
|
||||
if ( $field->get_multiple() != 'no') {
|
||||
if ( $metadatum->get_multiple() != 'no') {
|
||||
return ['multiple' => __('Core Metadata can not accept multiple values', 'tainacan')];
|
||||
}
|
||||
|
|
@ -61,7 +61,7 @@
|
|||
},
|
||||
props: {
|
||||
id: '',
|
||||
field: {
|
||||
metadatum: {
|
||||
type: Object
|
||||
},
|
||||
value: [String, Number, Array],
|
|
@ -1,17 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Field_Types;
|
||||
namespace Tainacan\Metadatum_Types;
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
use Tainacan\Helpers;
|
||||
/**
|
||||
* Class TainacanFieldType
|
||||
* Class TainacanMetadatumType
|
||||
*/
|
||||
class Date extends Field_Type {
|
||||
class Date extends Metadatum_Type {
|
||||
|
||||
function __construct(){
|
||||
// call field type constructor
|
||||
// call metadatum type constructor
|
||||
parent::__construct();
|
||||
$this->set_primitive_type('date');
|
||||
$this->set_component('tainacan-date');
|
||||
|
@ -23,9 +23,9 @@ class Date extends Field_Type {
|
|||
*/
|
||||
|
||||
public function render( $itemMetadata ){
|
||||
return '<tainacan-date field_id ="'.$itemMetadata->get_field()->get_id().'"
|
||||
return '<tainacan-date metadatum_id ="'.$itemMetadata->get_metadatum()->get_id().'"
|
||||
item_id="'.$itemMetadata->get_item()->get_id().'"
|
||||
value=\''.json_encode( $itemMetadata->get_value() ).'\'
|
||||
name="'.$itemMetadata->get_field()->get_name().'"></tainacan-date>';
|
||||
name="'.$itemMetadata->get_metadatum()->get_name().'"></tainacan-date>';
|
||||
}
|
||||
}
|
|
@ -1,36 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Field_Types;
|
||||
namespace Tainacan\Metadatum_Types;
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Class TainacanFieldType
|
||||
* Class TainacanMetadatumType
|
||||
*/
|
||||
abstract class Field_Type {
|
||||
abstract class Metadatum_Type {
|
||||
|
||||
|
||||
/**
|
||||
* Indicates the type of variable that this field type handles.
|
||||
* Indicates the type of variable that this metadatum type handles.
|
||||
*
|
||||
* This is used to relate Field types and filter types, so we know which filter types
|
||||
* will be available to be used for each field based on its Field Type
|
||||
* This is used to relate Metadatum types and filter types, so we know which filter types
|
||||
* will be available to be used for each metadatum based on its Metadatum Type
|
||||
*
|
||||
* For instance, the Filter Type "input text" may be used to search in any field that has
|
||||
* a Field Type with a string primitive type.
|
||||
* For instance, the Filter Type "input text" may be used to search in any metadatum that has
|
||||
* a Metadatum Type with a string primitive type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $primitive_type;
|
||||
|
||||
/**
|
||||
* Array of options specific to this field type. Stored in field_type_options property of the Field object
|
||||
* Array of options specific to this metadatum type. Stored in metadatum_type_options property of the Metadatum object
|
||||
* @var array
|
||||
*/
|
||||
private $options = [];
|
||||
|
||||
/**
|
||||
* The default values for the field type options array
|
||||
* The default values for the metadatum type options array
|
||||
* @var array
|
||||
*/
|
||||
private $default_options = [];
|
||||
|
@ -38,9 +38,9 @@ abstract class Field_Type {
|
|||
private $errors;
|
||||
|
||||
/**
|
||||
* Indicates whether this is a core Field Type or not
|
||||
* Indicates whether this is a core Metadatum Type or not
|
||||
*
|
||||
* Core field types are used by Title and description fields. These fields:
|
||||
* Core metadatum types are used by Title and description metadata. These metadata:
|
||||
* * Can only be used once, they belong to the repository and can not be deleted
|
||||
* * Its values are saved in th wp_post table, and not as post_meta
|
||||
*
|
||||
|
@ -48,12 +48,12 @@ abstract class Field_Type {
|
|||
private $core = false;
|
||||
|
||||
/**
|
||||
* Used by core field types to indicate where it should be saved
|
||||
* Used by core metadatum types to indicate where it should be saved
|
||||
*/
|
||||
private $related_mapped_prop = false;
|
||||
|
||||
/**
|
||||
* The name of the web component used by this field type
|
||||
* The name of the web component used by this metadatum type
|
||||
* @var string
|
||||
*/
|
||||
private $component;
|
||||
|
@ -126,9 +126,9 @@ abstract class Field_Type {
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the options for this field types, including default values for options
|
||||
* Gets the options for this metadatum types, including default values for options
|
||||
* that were not set yet.
|
||||
* @return array Field type options
|
||||
* @return array Metadatum type options
|
||||
*/
|
||||
public function get_options() {
|
||||
return array_merge($this->default_options, $this->options);
|
||||
|
@ -154,7 +154,7 @@ abstract class Field_Type {
|
|||
return [];
|
||||
}
|
||||
/**
|
||||
* generate the fields for this field type
|
||||
* generate the metadata for this metadatum type
|
||||
*/
|
||||
public function form(){
|
||||
|
||||
|
@ -179,12 +179,12 @@ abstract class Field_Type {
|
|||
/**
|
||||
* Validates the options Array
|
||||
*
|
||||
* This method should be declared by each field type sub classes
|
||||
* This method should be declared by each metadatum type sub classes
|
||||
*
|
||||
* @param \Tainacan\Entities\Field $field The field object that is beeing validated
|
||||
* @return true|Array True if optinos are valid. If invalid, returns an array where keys are the field keys and values are error messages.
|
||||
* @param \Tainacan\Entities\Metadatum $metadatum The metadatum object that is beeing validated
|
||||
* @return true|Array True if optinos are valid. If invalid, returns an array where keys are the metadatum keys and values are error messages.
|
||||
*/
|
||||
public function validate_options(\Tainacan\Entities\Field $field) {
|
||||
public function validate_options(\Tainacan\Entities\Metadatum $metadatum) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
},
|
||||
props: {
|
||||
id: '',
|
||||
field: {
|
||||
metadatum: {
|
||||
type: Object
|
||||
},
|
||||
value: [String, Number, Array],
|
|
@ -1,16 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Field_Types;
|
||||
namespace Tainacan\Metadatum_Types;
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Class TainacanFieldType
|
||||
* Class TainacanMetadatumType
|
||||
*/
|
||||
class Numeric extends Field_Type {
|
||||
class Numeric extends Metadatum_Type {
|
||||
|
||||
function __construct(){
|
||||
// call field type constructor
|
||||
// call metadatum type constructor
|
||||
parent::__construct();
|
||||
$this->set_primitive_type('float');
|
||||
$this->set_component('tainacan-numeric');
|
||||
|
@ -23,9 +23,9 @@ class Numeric extends Field_Type {
|
|||
|
||||
public function render( $itemMetadata ){
|
||||
return '<tainacan-numeric
|
||||
field_id ="'.$itemMetadata->get_field()->get_id().'"
|
||||
metadatum_id ="'.$itemMetadata->get_metadatum()->get_id().'"
|
||||
item_id="'.$itemMetadata->get_item()->get_id().'"
|
||||
value=\''.json_encode( $itemMetadata->get_value() ).'\'
|
||||
name="'.$itemMetadata->get_field()->get_name().'"></tainacan-numeric>';
|
||||
name="'.$itemMetadata->get_metadatum()->get_name().'"></tainacan-numeric>';
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@
|
|||
:message="$i18n.getHelperMessage('tainacan-relationship', 'collection_id')"/>
|
||||
</label>
|
||||
<b-select
|
||||
name="field_type_relationship[collection_id]"
|
||||
name="metadatum_type_relationship[collection_id]"
|
||||
placeholder="Select the collection to fetch items"
|
||||
v-model="collection"
|
||||
@change.native="emitValues()"
|
||||
|
@ -30,24 +30,24 @@
|
|||
|
||||
<transition name="fade">
|
||||
<div
|
||||
v-if="loadingFields"
|
||||
v-if="loadingMetadata"
|
||||
class="loading-spinner"/>
|
||||
<b-field
|
||||
v-if="hasFields"
|
||||
v-if="hasMetadata"
|
||||
:addons="false">
|
||||
<label class="label">
|
||||
{{ $i18n.get('label_fields_for_search') }}
|
||||
{{ $i18n.get('label_metadata_for_search') }}
|
||||
<help-button
|
||||
:title="$i18n.getHelperTitle('tainacan-relationship', 'search')"
|
||||
:message="$i18n.getHelperMessage('tainacan-relationship', 'search')"/>
|
||||
</label>
|
||||
<div class="block">
|
||||
<div
|
||||
v-for="(option, index) in fields"
|
||||
v-for="(option, index) in metadata"
|
||||
:key="index"
|
||||
class="field">
|
||||
<b-checkbox
|
||||
name="field_type_relationship[search][]"
|
||||
name="metadatum_type_relationship[search][]"
|
||||
v-model="modelSearch"
|
||||
:native-value="option.id">
|
||||
{{ option.name }}
|
||||
|
@ -88,18 +88,18 @@
|
|||
collection_id: [ Number ],
|
||||
repeated: [ String ],
|
||||
value: [ String, Object, Array ],
|
||||
field: [ String, Object ],
|
||||
metadatum: [ String, Object ],
|
||||
errors: [ String, Object, Array ]
|
||||
},
|
||||
data(){
|
||||
return {
|
||||
icon: '',
|
||||
collections:[],
|
||||
fields: [],
|
||||
metadata: [],
|
||||
loading: true,
|
||||
collection: '',
|
||||
hasFields: false,
|
||||
loadingFields: false,
|
||||
hasMetadata: false,
|
||||
loadingMetadata: false,
|
||||
modelRepeated: 'yes',
|
||||
modelSearch:[],
|
||||
collectionType: '',
|
||||
|
@ -110,10 +110,10 @@
|
|||
collection( value ){
|
||||
this.collection = value;
|
||||
if( value && value !== '' ) {
|
||||
this.fetchFieldsFromCollection(value);
|
||||
this.fetchMetadataFromCollection(value);
|
||||
} else {
|
||||
this.fields = [];
|
||||
this.hasFields = false;
|
||||
this.metadata = [];
|
||||
this.hasMetadata = false;
|
||||
this.modelSearch = [];
|
||||
|
||||
this.emitValues();
|
||||
|
@ -170,32 +170,32 @@
|
|||
this.$console.log(error);
|
||||
});
|
||||
},
|
||||
fetchFieldsFromCollection( value ){
|
||||
this.loadingFields = true;
|
||||
this.hasFields = false;
|
||||
fetchMetadataFromCollection( value ){
|
||||
this.loadingMetadata = true;
|
||||
this.hasMetadata = false;
|
||||
|
||||
axios.get('/collection/' + value + '/fields/')
|
||||
axios.get('/collection/' + value + '/metadata/')
|
||||
.then((res) => {
|
||||
this.loadingFields = false;
|
||||
let fields = res.data;
|
||||
this.loadingMetadata = false;
|
||||
let metadata = res.data;
|
||||
|
||||
if( fields.length > 0 ){
|
||||
this.fields = [];
|
||||
if( metadata.length > 0 ){
|
||||
this.metadata = [];
|
||||
|
||||
for( let field of fields ){
|
||||
if( field.field_type !== "Tainacan\\Field_Types\\Relationship"){
|
||||
this.fields.push( field );
|
||||
this.hasFields = true;
|
||||
this.checkFields()
|
||||
for( let metadatum of metadata ){
|
||||
if( metadatum.metadatum_type !== "Tainacan\\Metadatum_Types\\Relationship"){
|
||||
this.metadata.push( metadatum );
|
||||
this.hasMetadata = true;
|
||||
this.checkMetadata()
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
this.fields = [];
|
||||
this.hasFields = false;
|
||||
this.metadata = [];
|
||||
this.hasMetadata = false;
|
||||
this.$toast.open({
|
||||
duration: 4000,
|
||||
message: this.$i18n.get('info_warning_no_fields_found'),
|
||||
message: this.$i18n.get('info_warning_no_metadata_found'),
|
||||
position: 'is-bottom',
|
||||
type: 'is-danger'
|
||||
})
|
||||
|
@ -204,12 +204,12 @@
|
|||
this.emitValues();
|
||||
})
|
||||
.catch(() => {
|
||||
this.hasFields = false;
|
||||
this.hasMetadata = false;
|
||||
this.emitValues();
|
||||
});
|
||||
|
||||
},
|
||||
checkFields(){
|
||||
checkMetadata(){
|
||||
if( this.value && this.value.search.length > 0 ){
|
||||
this.modelSearch = this.value.search;
|
||||
} else {
|
|
@ -4,7 +4,7 @@
|
|||
:id="id"
|
||||
v-model="selected"
|
||||
:data="options"
|
||||
:maxtags="field.field.multiple === 'yes' ? 100 : 1"
|
||||
:maxtags="metadatum.metadatum.multiple === 'yes' ? 100 : 1"
|
||||
autocomplete
|
||||
attached
|
||||
:loading="loading"
|
||||
|
@ -21,9 +21,9 @@
|
|||
|
||||
export default {
|
||||
created(){
|
||||
let collectionId = ( this.field && this.field.field.field_type_options.collection_id ) ? this.field.field.field_type_options.collection_id : this.collection_id;
|
||||
if( this.field.value ){
|
||||
let query = qs.stringify({ postin: ( Array.isArray( this.field.value ) ) ? this.field.value : [ this.field.value ] });
|
||||
let collectionId = ( this.metadatum && this.metadatum.metadatum.metadatum_type_options.collection_id ) ? this.metadatum.metadatum.metadatum_type_options.collection_id : this.collection_id;
|
||||
if( this.metadatum.value ){
|
||||
let query = qs.stringify({ postin: ( Array.isArray( this.metadatum.value ) ) ? this.metadatum.value : [ this.metadatum.value ] });
|
||||
|
||||
axios.get('/collection/'+collectionId+'/items?' + query + '?nopaging=1')
|
||||
.then( res => {
|
||||
|
@ -36,13 +36,13 @@
|
|||
});
|
||||
}
|
||||
|
||||
if( this.field.field.field_type_options
|
||||
&& this.field.field.field_type_options.search.length > 0){
|
||||
axios.get('/collection/'+ collectionId +'/fields?context=edit')
|
||||
if( this.metadatum.metadatum.metadatum_type_options
|
||||
&& this.metadatum.metadatum.metadatum_type_options.search.length > 0){
|
||||
axios.get('/collection/'+ collectionId +'/metadata?context=edit')
|
||||
.then( res => {
|
||||
for (let item of res.data) {
|
||||
if( this.field.field.field_type_options.search.indexOf( item.id ) >= 0 )
|
||||
this.searchFields.push( item );
|
||||
if( this.metadatum.metadatum.metadatum_type_options.search.indexOf( item.id ) >= 0 )
|
||||
this.searchMetadata.push( item );
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
|
@ -58,13 +58,13 @@
|
|||
loading: false,
|
||||
collectionId: 0,
|
||||
inputValue: null,
|
||||
searchFields: [],
|
||||
searchMetadata: [],
|
||||
queryObject: {},
|
||||
itemsFound: []
|
||||
}
|
||||
},
|
||||
props: {
|
||||
field: {
|
||||
metadatum: {
|
||||
type: Object
|
||||
},
|
||||
collection_id: {
|
||||
|
@ -95,7 +95,7 @@
|
|||
this.$emit('blur');
|
||||
},
|
||||
search(query){
|
||||
if( this.selected.length > 0 && this.field.field.multiple === 'no'){
|
||||
if( this.selected.length > 0 && this.metadatum.metadatum.multiple === 'no'){
|
||||
return '';
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@
|
|||
let metaquery = this.mountQuery( query );
|
||||
this.loading = true;
|
||||
this.options = [];
|
||||
let collectionId = ( this.field && this.field.field.field_type_options.collection_id ) ? this.field.field.field_type_options.collection_id : this.collection_id;
|
||||
let collectionId = ( this.metadatum && this.metadatum.metadatum.metadatum_type_options.collection_id ) ? this.metadatum.metadatum.metadatum_type_options.collection_id : this.collection_id;
|
||||
axios.get('/collection/'+collectionId+'/items?' + qs.stringify( metaquery ))
|
||||
.then( res => {
|
||||
this.loading = false;
|
||||
|
@ -122,13 +122,13 @@
|
|||
},
|
||||
mountQuery( search ){
|
||||
let query = []
|
||||
if( this.searchFields.length > 0){
|
||||
if( this.searchMetadata.length > 0){
|
||||
query['metaquery'] = [];
|
||||
const metaquery = query['metaquery'];
|
||||
metaquery['relation'] = 'OR'
|
||||
for( let index in this.searchFields ){
|
||||
for( let index in this.searchMetadata ){
|
||||
metaquery[index] = {
|
||||
key: this.searchFields[index].id,
|
||||
key: this.searchMetadata[index].id,
|
||||
value: search
|
||||
}
|
||||
}
|
|
@ -1,16 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Field_Types;
|
||||
namespace Tainacan\Metadatum_Types;
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Class TainacanFieldType
|
||||
* Class TainacanMetadatumType
|
||||
*/
|
||||
class Relationship extends Field_Type {
|
||||
class Relationship extends Metadatum_Type {
|
||||
|
||||
function __construct(){
|
||||
// call field type constructor
|
||||
// call metadatum type constructor
|
||||
parent::__construct();
|
||||
$this->set_primitive_type('item');
|
||||
$this->set_component('tainacan-relationship');
|
||||
|
@ -45,14 +45,14 @@ class Relationship extends Field_Type {
|
|||
public function render( $itemMetadata ){
|
||||
return '<tainacan-relationship
|
||||
collection_id="' . $this->get_options()['collection_id'] . '"
|
||||
field_id ="'.$itemMetadata->get_field()->get_id().'"
|
||||
metadatum_id ="'.$itemMetadata->get_metadatum()->get_id().'"
|
||||
item_id="'.$itemMetadata->get_item()->get_id().'"
|
||||
value=\''.json_encode( $itemMetadata->get_value() ).'\'
|
||||
name="'.$itemMetadata->get_field()->get_name().'"></tainacan-relationship>';
|
||||
name="'.$itemMetadata->get_metadatum()->get_name().'"></tainacan-relationship>';
|
||||
}
|
||||
|
||||
public function validate_options(\Tainacan\Entities\Field $field) {
|
||||
if ( !in_array($field->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) )
|
||||
public function validate_options(\Tainacan\Entities\Metadatum $metadatum) {
|
||||
if ( !in_array($metadatum->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) )
|
||||
return true;
|
||||
|
||||
if (!empty($this->get_option('collection_id')) && !is_numeric($this->get_option('collection_id'))) {
|
||||
|
@ -68,7 +68,7 @@ class Relationship extends Field_Type {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the value of an Item_Metadata_Entity using a field of this field type as an html string
|
||||
* Return the value of an Item_Metadata_Entity using a metadatum of this metadatum type as an html string
|
||||
* @param Item_Metadata_Entity $item_metadata
|
||||
* @return string The HTML representation of the value, containing one or multiple items names, linked to the item page
|
||||
*/
|
|
@ -27,7 +27,7 @@
|
|||
export default {
|
||||
props: {
|
||||
value: [ String, Object, Array ],
|
||||
field: [ String, Object ],
|
||||
metadatum: [ String, Object ],
|
||||
errors: [ String, Object, Array ]
|
||||
},
|
||||
data() {
|
|
@ -30,7 +30,7 @@
|
|||
}
|
||||
},
|
||||
props: {
|
||||
field: {
|
||||
metadatum: {
|
||||
type: Object
|
||||
},
|
||||
options: {
|
||||
|
@ -44,9 +44,9 @@
|
|||
if ( this.options && this.options !== '' ){
|
||||
return this.options.split("\n");
|
||||
}
|
||||
else if ( this.field && this.field.field.field_type_options.options ) {
|
||||
const fields = this.field.field.field_type_options.options;
|
||||
return ( fields ) ? fields.split("\n") : [];
|
||||
else if ( this.metadatum && this.metadatum.metadatum.metadatum_type_options.options ) {
|
||||
const metadata = this.metadatum.metadatum.metadatum_type_options.options;
|
||||
return ( metadata ) ? metadata.split("\n") : [];
|
||||
}
|
||||
return [];
|
||||
}
|
|
@ -1,16 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Field_Types;
|
||||
namespace Tainacan\Metadatum_Types;
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Class TainacanFieldType
|
||||
* Class TainacanMetadatumType
|
||||
*/
|
||||
class Selectbox extends Field_Type {
|
||||
class Selectbox extends Metadatum_Type {
|
||||
|
||||
function __construct(){
|
||||
// call field type constructor
|
||||
// call metadatum type constructor
|
||||
parent::__construct();
|
||||
$this->set_primitive_type('string');
|
||||
$this->set_component('tainacan-selectbox');
|
||||
|
@ -37,18 +37,18 @@ class Selectbox extends Field_Type {
|
|||
$options = $this->get_option('options');
|
||||
return '<tainacan-selectbox
|
||||
options="' . $options . '"
|
||||
field_id ="'.$itemMetadata->get_field()->get_id().'"
|
||||
metadatum_id ="'.$itemMetadata->get_metadatum()->get_id().'"
|
||||
item_id="'.$itemMetadata->get_item()->get_id().'"
|
||||
value=\''.json_encode( $itemMetadata->get_value() ).'\'
|
||||
name="'.$itemMetadata->get_field()->get_name().'"></tainacan-selectbox>';
|
||||
name="'.$itemMetadata->get_metadatum()->get_name().'"></tainacan-selectbox>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Tainacan\Entities\Field $field
|
||||
* @param \Tainacan\Entities\Metadatum $metadatum
|
||||
* @return array|bool true if is validate or array if has error
|
||||
*/
|
||||
public function validate_options(\Tainacan\Entities\Field $field) {
|
||||
if ( !in_array($field->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) )
|
||||
public function validate_options(\Tainacan\Entities\Metadatum $metadatum) {
|
||||
if ( !in_array($metadatum->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) )
|
||||
return true;
|
||||
|
||||
if ( empty($this->get_option('options')) ) {
|
|
@ -2,43 +2,43 @@
|
|||
<b-field
|
||||
:addons="false"
|
||||
:message="getErrorMessage"
|
||||
:type="fieldTypeMessage">
|
||||
:type="metadatumTypeMessage">
|
||||
<span
|
||||
class="collapse-handle"
|
||||
@click="$emit('changeCollapse', fieldTypeMessage != 'is-danger' ? !isCollapsed : true)">
|
||||
@click="$emit('changeCollapse', metadatumTypeMessage != 'is-danger' ? !isCollapsed : true)">
|
||||
<b-icon
|
||||
type="is-secondary"
|
||||
:icon="isCollapsed || fieldTypeMessage == 'is-danger' ? 'menu-down' : 'menu-right'" />
|
||||
<label class="label">{{ field.field.name }}</label>
|
||||
:icon="isCollapsed || metadatumTypeMessage == 'is-danger' ? 'menu-down' : 'menu-right'" />
|
||||
<label class="label">{{ metadatum.metadatum.name }}</label>
|
||||
<span
|
||||
v-if="field.field.required == 'yes'"
|
||||
class="required-field-asterisk"
|
||||
:class="fieldTypeMessage">*</span>
|
||||
<span class="field-type">({{ $i18n.get(field.field.field_type_object.component) }})</span>
|
||||
v-if="metadatum.metadatum.required == 'yes'"
|
||||
class="required-metadatum-asterisk"
|
||||
:class="metadatumTypeMessage">*</span>
|
||||
<span class="metadatum-type">({{ $i18n.get(metadatum.metadatum.metadatum_type_object.component) }})</span>
|
||||
<help-button
|
||||
:title="field.field.name"
|
||||
:message="field.field.description"/>
|
||||
:title="metadatum.metadatum.name"
|
||||
:message="metadatum.metadatum.description"/>
|
||||
</span>
|
||||
<div
|
||||
v-show="isCollapsed || fieldTypeMessage == 'is-danger'"
|
||||
v-if="isTextInputComponent( field.field.field_type_object.component )">
|
||||
v-show="isCollapsed || metadatumTypeMessage == 'is-danger'"
|
||||
v-if="isTextInputComponent( metadatum.metadatum.metadatum_type_object.component )">
|
||||
<component
|
||||
:id="field.field.field_type_object.component + '-' + field.field.slug"
|
||||
:is="field.field.field_type_object.component"
|
||||
:id="metadatum.metadatum.metadatum_type_object.component + '-' + metadatum.metadatum.slug"
|
||||
:is="metadatum.metadatum.metadatum_type_object.component"
|
||||
v-model="inputs[0]"
|
||||
:field="field"
|
||||
:metadatum="metadatum"
|
||||
@blur="changeValue()"/>
|
||||
<div v-if="field.field.multiple == 'yes'">
|
||||
<div v-if="metadatum.metadatum.multiple == 'yes'">
|
||||
<div
|
||||
v-if="index > 0"
|
||||
v-for="(input, index) in inputsList "
|
||||
:key="index"
|
||||
class="multiple-inputs">
|
||||
<component
|
||||
:id="field.field.field_type_object.component + '-' + field.field.slug"
|
||||
:is="field.field.field_type_object.component"
|
||||
:id="metadatum.metadatum.metadatum_type_object.component + '-' + metadatum.metadatum.slug"
|
||||
:is="metadatum.metadatum.metadatum_type_object.component"
|
||||
v-model="inputs[index]"
|
||||
:field="field"
|
||||
:metadatum="metadatum"
|
||||
@blur="changeValue()"/><a
|
||||
class="button"
|
||||
v-if="index > 0"
|
||||
|
@ -53,10 +53,10 @@
|
|||
v-show="isCollapsed"
|
||||
v-else>
|
||||
<component
|
||||
:id="field.field.field_type_object.component + '-' + field.field.slug"
|
||||
:is="field.field.field_type_object.component"
|
||||
:id="metadatum.metadatum.metadatum_type_object.component + '-' + metadatum.metadatum.slug"
|
||||
:is="metadatum.metadatum.metadatum_type_object.component"
|
||||
v-model="inputs"
|
||||
:field="field"
|
||||
:metadatum="metadatum"
|
||||
@blur="changeValue()"/>
|
||||
</div>
|
||||
</b-field>
|
||||
|
@ -68,15 +68,15 @@
|
|||
export default {
|
||||
name: 'TainacanFormItem',
|
||||
props: {
|
||||
field: {
|
||||
metadatum: {
|
||||
type: Object
|
||||
},
|
||||
isCollapsed: true // Field Collapses
|
||||
isCollapsed: true // Metadatum Collapses
|
||||
},
|
||||
data(){
|
||||
return {
|
||||
inputs: [],
|
||||
fieldTypeMessage:''
|
||||
metadatumTypeMessage:''
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
@ -86,10 +86,10 @@
|
|||
getErrorMessage() {
|
||||
|
||||
let msg = '';
|
||||
let errors = eventBus.getErrors(this.field.field.id);
|
||||
let errors = eventBus.getErrors(this.metadatum.metadatum.id);
|
||||
|
||||
if ( errors) {
|
||||
this.setFieldTypeMessage('is-danger');
|
||||
this.setMetadatumTypeMessage('is-danger');
|
||||
for (let error of errors) {
|
||||
for (let index of Object.keys(error)) {
|
||||
// this.$console.log(index);
|
||||
|
@ -97,7 +97,7 @@
|
|||
}
|
||||
}
|
||||
} else {
|
||||
this.setFieldTypeMessage('');
|
||||
this.setMetadatumTypeMessage('');
|
||||
}
|
||||
|
||||
return msg;
|
||||
|
@ -108,15 +108,15 @@
|
|||
},
|
||||
methods: {
|
||||
changeValue(){
|
||||
eventBus.$emit('input', { item_id: this.field.item.id, field_id: this.field.field.id, values: this.inputs } );
|
||||
eventBus.$emit('input', { item_id: this.metadatum.item.id, metadatum_id: this.metadatum.metadatum.id, values: this.inputs } );
|
||||
},
|
||||
getValue(){
|
||||
if (this.field.value instanceof Array) {
|
||||
this.inputs = this.field.value;
|
||||
if (this.metadatum.value instanceof Array) {
|
||||
this.inputs = this.metadatum.value;
|
||||
if (this.inputs.length === 0)
|
||||
this.inputs.push('');
|
||||
} else {
|
||||
this.field.value == null || this.field.value == undefined ? this.inputs.push('') : this.inputs.push(this.field.value);
|
||||
this.metadatum.value == null || this.metadatum.value == undefined ? this.inputs.push('') : this.inputs.push(this.metadatum.value);
|
||||
}
|
||||
},
|
||||
addInput(){
|
||||
|
@ -131,8 +131,8 @@
|
|||
let array = ['tainacan-relationship','tainacan-category'];
|
||||
return !( array.indexOf( component ) >= 0 );
|
||||
},
|
||||
setFieldTypeMessage( message ){
|
||||
this.fieldTypeMessage = message;
|
||||
setMetadatumTypeMessage( message ){
|
||||
this.metadatumTypeMessage = message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -156,7 +156,7 @@
|
|||
margin-left: 18px;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
.field-type {
|
||||
.metadatum-type {
|
||||
font-size: 13px;
|
||||
font-weight: 400;
|
||||
color: $gray;
|
|
@ -20,7 +20,7 @@
|
|||
}
|
||||
},
|
||||
props: {
|
||||
field: {
|
||||
metadatum: {
|
||||
type: Object
|
||||
},
|
||||
value: [String, Number, Array],
|
|
@ -1,16 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Field_Types;
|
||||
namespace Tainacan\Metadatum_Types;
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Class TainacanFieldType
|
||||
* Class TainacanMetadatumType
|
||||
*/
|
||||
class Text extends Field_Type {
|
||||
class Text extends Metadatum_Type {
|
||||
|
||||
function __construct(){
|
||||
// call field type constructor
|
||||
// call metadatum type constructor
|
||||
parent::__construct();
|
||||
parent::set_primitive_type('string');
|
||||
parent::set_component('tainacan-text');
|
||||
|
@ -22,9 +22,9 @@ class Text extends Field_Type {
|
|||
*/
|
||||
|
||||
public function render( $itemMetadata ){
|
||||
return '<tainacan-text field_id ="'.$itemMetadata->get_field()->get_id().'"
|
||||
return '<tainacan-text metadatum_id ="'.$itemMetadata->get_metadatum()->get_id().'"
|
||||
item_id="'.$itemMetadata->get_item()->get_id().'"
|
||||
value=\''.json_encode( $itemMetadata->get_value() ).'\'
|
||||
name="'.$itemMetadata->get_field()->get_name().'"></tainacan-text>';
|
||||
name="'.$itemMetadata->get_metadatum()->get_name().'"></tainacan-text>';
|
||||
}
|
||||
}
|
|
@ -23,7 +23,7 @@
|
|||
},
|
||||
props: {
|
||||
id: '',
|
||||
field: {
|
||||
metadatum: {
|
||||
type: Object
|
||||
},
|
||||
value: [String, Number, Array],
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue