Changes field to metadatum and fields to metadata

This commit is contained in:
weryques 2018-06-11 12:10:07 -03:00
parent 90ed143980
commit 8ba7478287
169 changed files with 5689 additions and 5618 deletions

1
.gitignore vendored
View File

@ -27,3 +27,4 @@ report.txt
.tmp .tmp
src/assets/css/tainacan-embeds.css src/assets/css/tainacan-embeds.css
src/assets/css/tainacan-embeds.css.map src/assets/css/tainacan-embeds.css.map
demosaved.csv

View File

@ -1,16 +1,16 @@
# Fields # Metadata
## Field Repository ## Metadatum Repository
<!-- BEGIN DOC-COMMENT H3 src/classes/repositories/class-tainacan-fields.php --> <!-- BEGIN DOC-COMMENT H3 src/classes/repositories/class-tainacan-metadata.php -->
### `class Fields extends Repository` ### `class Metadata extends Repository`
Class Fields Class Metadata
### `protected function __construct()` ### `protected function __construct()`
Register specific hooks for field repository Register specific hooks for metadatum repository
### `public function get_cpt_labels()` ### `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()` ### `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 **Returns:** `string` — the value of constant
### `public function register_field_type( $class_name )` ### `public function register_field_type( $class_name )`
register field types class on array of types register metadatum types class on array of types
**Parameters:** **Parameters:**
@ -36,7 +36,7 @@ register field types class on array of types
### `public function unregister_field_type( $class_name )` ### `public function unregister_field_type( $class_name )`
register field types class on array of types register metadatum types class on array of types
**Parameters:** **Parameters:**
@ -45,21 +45,21 @@ register field types class on array of types
### `public function fetch( $args, $output = null )` ### `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:** **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) * `$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)` ### `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:** **Parameters:**
@ -68,11 +68,11 @@ fetch field by collection, searches all field available
* `$args` — array — WP_Query args plus disabled_fields * `$args` — array — WP_Query args plus disabled_fields
* `$output` — string — The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values) * `$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 )` ### `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 * `Response` — $result — from method fetch
* `$collection` — Entities\Collection * `$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 **Returns:** `array` — or WP_Query ordinate
### `public function insert($field)` ### `public function insert($metadatum)`
{@inheritDoc} {@inheritDoc}
**Parameters:** **Parameters:**
* `$field` — \Tainacan\Entities\Field * `$metadatum` — \Tainacan\Entities\Metadatum
**Returns:** \Tainacan\Entities\Field **Returns:** \Tainacan\Entities\Metadatum
### `public function update($object, $new_values = null)` ### `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')` ### `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:** **Parameters:**
* `string` — $output — CLASS | NAME * `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 )` ### `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 )` ### `public function disable_delete_core_fields( $before, $post )`
block user from remove core fields block user from remove core metadata
**Parameters:** **Parameters:**
@ -135,7 +135,7 @@ block user from remove core fields
### `public function force_delete_core_fields( $before, $post, $force_delete )` ### `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:** **Parameters:**
@ -159,72 +159,72 @@ returns all core items from a specific collection
### `public function insert_array_field( $data )` ### `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:** **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 **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. 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:** **Parameters:**
* `$field` — [type] — [description] * `$metadatum` — [type] — [description]
**Returns:** `[type]` — [description] **Returns:** `[type]` — [description]
<!-- END DOC-COMMENT --> <!-- END DOC-COMMENT -->
## Field Entity ## Metadatum Entity
<!-- BEGIN DOC-COMMENT H3 src/classes/entities/class-tainacan-field.php --> <!-- BEGIN DOC-COMMENT H3 src/classes/entities/class-tainacan-metadatum.php -->
### `class Field extends Entity` ### `class Metadatum extends Entity`
Represents the Entity Field Represents the Entity Metadatum
### `protected $repository = 'Fields'` ### `protected $repository = 'Metadata'`
{@inheritDoc} {@inheritDoc}
### `function get_name()` ### `function get_name()`
Return the field name Return the metadatum name
**Returns:** string **Returns:** string
### `function get_slug()` ### `function get_slug()`
Get field slug Get metadatum slug
**Returns:** string **Returns:** string
### `function get_order()` ### `function get_order()`
Return the field order type Return the metadatum order type
**Returns:** string **Returns:** string
@ -238,21 +238,21 @@ Return the parent ID
### `function get_description()` ### `function get_description()`
Return the field description Return the metadatum description
**Returns:** string **Returns:** string
### `function get_required()` ### `function get_required()`
Return if is a required field Return if is a required metadatum
**Returns:** boolean **Returns:** boolean
### `function get_multiple()` ### `function get_multiple()`
Return if is a multiple field Return if is a multiple metadatum
**Returns:** boolean **Returns:** boolean
@ -266,7 +266,7 @@ Return the cardinality
### `function get_collection_key()` ### `function get_collection_key()`
Return if field is key Return if metadatum is key
**Returns:** boolean **Returns:** boolean
@ -280,35 +280,35 @@ Return the mask
### `function get_default_value()` ### `function get_default_value()`
Return the field default value Return the metadatum default value
**Returns:** `string` — || integer **Returns:** `string` — || integer
### `function get_field_type_object()` ### `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()` ### `function get_field_type()`
Return the class name for the field type Return the class name for the metadatum type
**Returns:** `string` — The **Returns:** `string` — The
### `function get_field_type_options()` ### `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)` ### `function set_name($value)`
Set the field name Set the metadatum name
**Parameters:** **Parameters:**
@ -319,14 +319,14 @@ Set the field name
### `function get_accept_suggestion()` ### `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 **Returns:** bool
### `function set_slug($value)` ### `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) 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)` ### `function set_order($value)`
Set manually the order of the field Set manually the order of the metadatum
**Parameters:** **Parameters:**
@ -350,7 +350,7 @@ Set manually the order of the field
### `function set_parent($value)` ### `function set_parent($value)`
Set the field parent ID Set the metadatum parent ID
**Parameters:** **Parameters:**
@ -361,7 +361,7 @@ Set the field parent ID
### `function set_description($value)` ### `function set_description($value)`
Set field description Set metadatum description
**Parameters:** **Parameters:**
@ -372,7 +372,7 @@ Set field description
### `function set_required( $value )` ### `function set_required( $value )`
Allow the field be required Allow the metadatum be required
**Parameters:** **Parameters:**
@ -383,7 +383,7 @@ Allow the field be required
### `function set_multiple( $value )` ### `function set_multiple( $value )`
Allow multiple fields Allow multiple metadata
**Parameters:** **Parameters:**
@ -394,7 +394,7 @@ Allow multiple fields
### `function set_cardinality( $value )` ### `function set_cardinality( $value )`
The number of possible fields The number of possible metadata
**Parameters:** **Parameters:**
@ -416,7 +416,7 @@ Define if the value is key on the collection
### `function set_mask( $value )` ### `function set_mask( $value )`
Set mask for the field Set mask for the metadatum
**Parameters:** **Parameters:**
@ -449,23 +449,23 @@ Set default value
### `public function set_field_type( $value )` ### `public function set_field_type( $value )`
set the field type class name set the metadatum type class name
**Parameters:** **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 )` ### `function set_accept_suggestion( $value )`
Set if this field allow community suggestions Set if this metadatum allow community suggestions
**Parameters:** **Parameters:**
* `$value` — bool * `$value` — bool
### `function set_field_type_options( $value )` ### `function set_field_type_options( $value )`
Set Field type options Set Metadatum type options
**Parameters:** **Parameters:**
@ -476,9 +476,9 @@ Set Field type options
### `public function get_enabled_for_collection()` ### `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 } {@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 **Returns:** `bool` — valid or not

View File

@ -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 )` ### `public function register_filter_type( $class_name )`
register field types class on array of types register metadatum types class on array of types
**Parameters:** **Parameters:**
@ -37,7 +37,7 @@ register field types class on array of types
### `public function deregister_filter_type( $class_name )` ### `public function deregister_filter_type( $class_name )`
register field types class on array of types register metadatum types class on array of types
**Parameters:** **Parameters:**
@ -64,7 +64,7 @@ fetch only supported filters for the type specified
**Parameters:** **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 **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 * `$args` — array — WP_Query args plus disabled_fields
* `$output` — string — The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values) * `$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 )` ### `public function order_result( $result, Entities\Collection $collection )`
@ -141,10 +141,10 @@ Return the filter color
### `function get_field()` ### `function get_field()`
Return the field Return the metadatum
**Returns:** Field **Returns:** Metadatum
### `function get_filter_type_object()` ### `function get_filter_type_object()`
@ -213,7 +213,7 @@ Define the filter color
### `function set_field( $value )` ### `function set_field( $value )`
Define the filter field Define the filter metadatum
**Returns:** void **Returns:** void
@ -231,7 +231,7 @@ Save the filter type class name
{@inheritdoc } {@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 **Returns:** `bool` — valid or not

View File

@ -5,9 +5,9 @@
<!-- BEGIN DOC-COMMENT H3 src/classes/repositories/class-tainacan-item-metadata.php --> <!-- 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()) )` ### `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)` ### `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 )` ### `public function fetch($object, $output = null )`
Fetch Item Field objects related to an Item Fetch Item Metadatum objects related to an Item
**Parameters:** **Parameters:**
@ -35,7 +35,7 @@ Fetch Item Field objects related to an Item
### `public function get_value(Entities\Item_Metadata_Entity $item_metadata)` ### `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:** **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)` ### `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:** **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)` ### `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:** **Parameters:**
* `$item_metadata` — Entities\Item_Metadata_Entity * `$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 --> <!-- BEGIN DOC-COMMENT H3 src/classes/entities/class-tainacan-item-metadata-entity.php -->
### `class Item_Metadata_Entity extends Entity` ### `class Item_Metadata_Entity extends Entity`
Represents the Item Field Entity Represents the Item Metadatum Entity
### `protected $repository = 'Item_Metadata'` ### `protected $repository = 'Item_Metadata'`
{@inheritDoc} {@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:** **Parameters:**
* `$item` — Item — Item Entity * `$item` — Item — Item Entity
* `$field` — Field — Field Entity * `$metadatum` — Metadatum — Metadatum Entity
* `$meta_id` — int — ID for a specific meta row * `$meta_id` — int — ID for a specific meta row
### `function set_item(Item $item)` ### `function set_item(Item $item)`
@ -108,7 +108,7 @@ Define the item
### `function set_value($value)` ### `function set_value($value)`
Define the field value Define the metadatum value
**Parameters:** **Parameters:**
@ -117,14 +117,14 @@ Define the field value
**Returns:** void **Returns:** void
### `function set_field(Field $field)` ### `function set_field(Metadatum $metadatum)`
Define the field Define the metadatum
**Parameters:** **Parameters:**
* `$field` — Field * `$metadatum` — Metadatum
**Returns:** void **Returns:** void
@ -132,7 +132,7 @@ Define the field
Set the specific meta ID for this metadata. 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:** **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)` ### `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:** **Parameters:**
@ -159,49 +159,49 @@ Return the item
### `function get_field()` ### `function get_field()`
Return the field Return the metadatum
**Returns:** Field **Returns:** Metadatum
### `function get_meta_id()` ### `function get_meta_id()`
Return the meta_id Return the meta_id
**Returns:** Field **Returns:** Metadatum
### `function get_parent_meta_id()` ### `function get_parent_meta_id()`
Return the meta_id Return the meta_id
**Returns:** Field **Returns:** Metadatum
### `function get_value()` ### `function get_value()`
Return the field value Return the metadatum value
**Returns:** `string` — | integer **Returns:** `string` — | integer
### `function is_multiple()` ### `function is_multiple()`
Return true if field is multiple, else return false Return true if metadatum is multiple, else return false
**Returns:** boolean **Returns:** boolean
### `function is_collection_key()` ### `function is_collection_key()`
Return true if field is key Return true if metadatum is key
**Returns:** boolean **Returns:** boolean
### `function is_required()` ### `function is_required()`
Return true if field is required Return true if metadatum is required
**Returns:** boolean **Returns:** boolean

View File

@ -240,9 +240,9 @@ Define the description
Return a List of ItemMetadata objects 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 **Returns:** `array` — Array of ItemMetadata objects

View File

@ -6,9 +6,9 @@ But sometimes you dont want just to have your collections browsable via web, you
## Mapping ## 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). 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. 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. Tainacan makes it very easy to developers to create new exporters and publish them as plugins anyone can use.
## Exposing ## 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. 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.

View File

@ -1,5 +1,5 @@
* everything auto draft * everything auto draft
* post_meta of deleted fields * post_meta of deleted metadata
* 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 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) * orphan terms (with taxonomy that does not exist)

View File

@ -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, 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. 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 ## Set options
@ -79,12 +79,12 @@ From that point forward, the importer will behave just as if it was using the fi
## Mapping ## 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() { function get_fields() {
return [ return [
'title', 'title',
@ -103,7 +103,7 @@ public function get_fields(){
## Importing Collection Structure and Mapping ## 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`. 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 Example
``` ```
function create_fields_and_mapping() { function create_fields_and_mapping() {
$fields_repository = \Tainacan\Repositories\Fields::get_instance(); $metadata_repository = \Tainacan\Repositories\Metadata::get_instance();
$newField1 = new \Tainacan\Entities\Field(); $newMetadatum1 = new \Tainacan\Entities\Metadatum();
$newField1->set_name = 'New Field'; $newMetadatum1->set_name = 'New Metadatum';
$newField1->set_field_type = 'Tainacan\Field_Types\Text'; $newMetadatum1->set_field_type = 'Tainacan\Metadatum_Types\Text';
$newField1->set_collection($this->collection); $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(); $source_fields = $this->get_fields();
$this->set_mapping([ $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. 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. In the end, a report is generated with all the logs generated in the process.

View File

@ -1,6 +1,6 @@
# Tainacan Internal API # 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. 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) * [Collections Reference](class-reference-collections.md)
* [Items Reference](class-reference-items.md) * [Items Reference](class-reference-items.md)
* [Item Metadata Reference](class-reference-item-metadata.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) * [Filters Reference](class-reference-filters.md)
* [Taxonomies Reference](class-reference-taxonomies.md) * [Taxonomies Reference](class-reference-taxonomies.md)
* [Terms Reference](class-reference-terms.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. 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 ```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. 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. 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: 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 ```PHP
$field->get_name(); // returns the field name $metadatum->get_name(); // returns the metadatum name
$field->get_required(); // returns the required value $metadatum->get_required(); // returns the required value
$field->set_name('new name'); $metadatum->set_name('new name');
$field->set_required('yes'); $metadatum->set_required('yes');
``` ```
Tainacan will automatically map the values of the attributes to and from where they are stored. 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: 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 ```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. 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: 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 ```PHP
$repo = Tainacan\Repositories\Fields::get_instance(); $repo = Tainacan\Repositories\Metadata::get_instance();
$fields = $repo->fetch([ $metadata = $repo->fetch([
'required' => 'yes' 'required' => 'yes'
]); ]);
// is the same as // is the same as
$fields = $repo->fetch([ $metadata = $repo->fetch([
'meta_query' => [ 'meta_query' => [
[ [
'key' => 'required', '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. `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 ```PHP
// Considering $item is an existing Item Entity an $field an existing Field Entity // Considering $item is an existing Item Entity an $metadatum an existing Field Entity
$itemMetadada = new \Tainacan\Entities\ItemMetadataEntity($item, $field); $itemMetadada = new \Tainacan\Entities\ItemMetadataEntity($item, $metadatum);
$itemMetadata->set_value('Red'); $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. 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 ```PHP
@ -239,10 +239,10 @@ $compoundValue = $compoundItemMeta->get_value();
// This is an array of ItemMetadata Entities // 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( $childItemMeta instanceof \Tainacan\Entities\ItemMetadataEntity ); // true
var_dump( $field_id == $childItemMeta->get_field()->get_id() ); // true var_dump( $metadatum_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(); 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( $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 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. 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 Validate Field -> call validate_options() of the Field type

View File

@ -3,21 +3,21 @@
The typical workflow when you create a Digital Repository with Tainacan is: The typical workflow when you create a Digital Repository with Tainacan is:
* Create a collection * 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 * Choose which filters will be used when browsing the collection
* Insert items to the collection or import them from an external source * Insert items to the collection or import them from an external source
## Collections ## 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
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. 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 ## 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. Filters give the ability to the user to filter items in a collection using a Filter Type.
## Filter Types ## 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. 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. 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 ### Thematic Collections

View File

@ -1,6 +1,6 @@
# Mapping Standards # 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 ## Structure
@ -10,20 +10,20 @@ A Mapping Standard has the following attributes.
The name of the Mapping Standard. 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 * Label - The human readable name
* URI - The URI of this term/attribute in the origin Ontoloy/Vocabulary * 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 ### Context URL / Vocab URL
@ -38,7 +38,7 @@ The Class of the ontology that this mapping refers to. For example `CreativeWork
``` ```
{ {
'name': 'Dublin Core', 'name': 'Dublin Core',
'fields': { 'metadata': {
{ {
'name': 'title', 'name': 'title',
'label': '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', 'name': 'Schema.org Creative Works',
'fields': { 'metadata': {
{ {
'name': 'name', 'name': 'name',
'label': 'Name', 'label': 'Name',

View File

@ -209,7 +209,7 @@ Allows to view Items marked as private and its items.
### Categories ### Categories
### Fields ### Metadata
### Filters ### Filters

View File

@ -11,8 +11,8 @@ A REST API for Tainacan Plugin. This API uses the Wordpress REST API.
1. [Collections](#collections) 1. [Collections](#collections)
1. [Items](#items) 1. [Items](#items)
1. [Fields](#fields) 1. [Metadata](#metadata)
1. [Field Types](#field-types) 1. [Metadatum Types](#metadatum-types)
1. [Item Metadata](#item-metadata) 1. [Item Metadata](#item-metadata)
1. [Taxonomies](#taxonomies) 1. [Taxonomies](#taxonomies)
1. [Filters](#filters) 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. 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 ```javascript
{ {
"name": "string", "name": "string",
"description": "string", "description": "string",
"field_type": "string", "metadatum_type": "string",
"order": "string", "order": "string",
"parent": "integer", "parent": "integer",
"required": "string", "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. 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: 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. 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. 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. In body of requisition pass a JSON with the attributes you need to update.
------ ------
#### Field Types #### Metadatum Types
1. Route `wp-json/tainacan/v2/field-types` 1. Route `wp-json/tainacan/v2/metadatum-types`
1. Endpoint: 1. Endpoint:
1. GET (Fetch all field types) 1. GET (Fetch all metadatum types)
------ ------
#### Item Metadata #### 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: 1. Endpoints:
@ -271,7 +271,7 @@ A REST API for Tainacan Plugin. This API uses the Wordpress REST API.
------ ------
#### Filters #### 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: 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. 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: 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. 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: Example of JSON passed in body for creating a filter:

5072
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -132,7 +132,7 @@ class Admin {
global $TAINACAN_BASE_URL; global $TAINACAN_BASE_URL;
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance(); $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_Filters = \Tainacan\Repositories\Filters::get_instance();
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance(); $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
@ -141,7 +141,7 @@ class Admin {
$entities_labels = [ $entities_labels = [
'collections' => $Tainacan_Collections->get_cpt_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(), 'filters' => $Tainacan_Filters->get_cpt_labels(),
'items' => $Tainacan_Items->get_cpt_labels(), 'items' => $Tainacan_Items->get_cpt_labels(),
'taxonomies' => $Tainacan_Taxonomies->get_cpt_labels(), 'taxonomies' => $Tainacan_Taxonomies->get_cpt_labels(),
@ -183,21 +183,21 @@ class Admin {
$maps = [ $maps = [
'collections' => $Tainacan_Collections->get_map(), 'collections' => $Tainacan_Collections->get_map(),
'fields' => $Tainacan_Fields->get_map(), 'metadata' => $Tainacan_Metadata->get_map(),
'filters' => $Tainacan_Filters->get_map(), 'filters' => $Tainacan_Filters->get_map(),
'items' => $Tainacan_Items->get_map(), 'items' => $Tainacan_Items->get_map(),
'taxonomies' => $Tainacan_Taxonomies->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( $maps as $type => $map ){
foreach ( $map as $field => $details){ foreach ( $map as $metadatum => $details){
$settings['i18n']['helpers_label'][$type][$field] = [ 'title' => $details['title'], 'description' => $details['description'] ]; $settings['i18n']['helpers_label'][$type][$metadatum] = [ 'title' => $details['title'], 'description' => $details['description'] ];
} }
} }
foreach ( $field_types as $index => $field_type){ foreach ( $metadatum_types as $index => $metadatum_type){
$class = new $field_type; $class = new $metadatum_type;
$settings['i18n']['helpers_label'][$class->get_component()] = $class->get_form_labels(); $settings['i18n']['helpers_label'][$class->get_component()] = $class->get_form_labels();
} }

View File

@ -3,8 +3,8 @@
<div class="columns is-multiline tnc-advanced-search-container"> <div class="columns is-multiline tnc-advanced-search-container">
<div <div
v-for="searchField in totalSearchMetadata" v-for="searchMetadatum in totalSearchMetadata"
:key="searchField" :key="searchMetadatum"
class="field column is-12 tainacan-form"> class="field column is-12 tainacan-form">
<b-field <b-field
@ -12,7 +12,7 @@
grouped> grouped>
<b-field class="column"> <b-field class="column">
<b-select <b-select
@input="addToAdvancedSearchQuery($event, 'field_id', searchField)"> @input="addToAdvancedSearchQuery($event, 'field_id', searchMetadatum)">
<option <option
v-for="metadata in metadataList" v-for="metadata in metadataList"
v-if="metadata.enabled" v-if="metadata.enabled"
@ -24,12 +24,12 @@
<b-field class="column is-two-thirds"> <b-field class="column is-two-thirds">
<b-input <b-input
@input="addValueToAdvancedSearchQuery($event, 'value', searchField)"/> @input="addValueToAdvancedSearchQuery($event, 'value', searchMetadatum)"/>
</b-field> </b-field>
<b-field class="column"> <b-field class="column">
<b-select <b-select
@input="addToAdvancedSearchQuery($event, 'compare', searchField)"> @input="addToAdvancedSearchQuery($event, 'compare', searchMetadatum)">
<option <option
v-for="(opt, key) in compare" v-for="(opt, key) in compare"
:value="key" :value="key"
@ -52,7 +52,7 @@
<a <a
@click="addSearchMetadata" @click="addSearchMetadata"
class="is-secondary is-small"> class="is-secondary is-small">
{{ $i18n.get('add_more_one_search_field') }}</a> {{ $i18n.get('add_more_one_search_metadatum') }}</a>
</div> </div>
</div> </div>
@ -71,7 +71,7 @@
</div> </div>
</div> </div>
</div> </div>
<pre>{{ advancedSearchQuery }}</pre> <!-- <pre>{{ advancedSearchQuery }}</pre> -->
</div> </div>
</template> </template>

View File

@ -370,38 +370,4 @@
} }
</script> </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>

View File

@ -47,7 +47,7 @@
<b-field <b-field
:addons="false" :addons="false"
:label="$i18n.get('label_header_image')"> :label="$i18n.get('label_header_image')">
<div class="thumbnail-field"> <div class="thumbnail-field">
<a <a
class="button is-rounred is-secondary" class="button is-rounred is-secondary"
id="button-edit-header-image" id="button-edit-header-image"
@ -438,8 +438,8 @@ export default {
'fetchUsers', 'fetchUsers',
'fetchCollectionsForParent' 'fetchCollectionsForParent'
]), ]),
...mapActions('fields', [ ...mapActions('metadata', [
'fetchFields' 'fetchMetadata'
]), ]),
onSubmit() { onSubmit() {
this.isLoading = true; this.isLoading = true;

View File

@ -10,7 +10,7 @@
<label class="label is-inline"> <label class="label is-inline">
{{ $i18n.get('label_name') }} {{ $i18n.get('label_name') }}
<span <span
class="required-field-asterisk" class="required-metadatum-asterisk"
:class="formErrors['name'] != undefined ? 'is-danger' : ''">*</span> :class="formErrors['name'] != undefined ? 'is-danger' : ''">*</span>
<help-button <help-button
:title="$i18n.getHelperTitle('filters', 'name')" :title="$i18n.getHelperTitle('filters', 'name')"

View File

@ -16,7 +16,7 @@
<!-- Status -------------------------------- --> <!-- Status -------------------------------- -->
<div class="section-label"> <div class="section-label">
<label>{{ $i18n.get('label_status') }}</label> <label>{{ $i18n.get('label_status') }}</label>
<span class="required-field-asterisk">*</span> <span class="required-metadatum-asterisk">*</span>
<help-button <help-button
:title="$i18n.getHelperTitle('items', 'status')" :title="$i18n.getHelperTitle('items', 'status')"
:message="$i18n.getHelperMessage('items', 'status')"/> :message="$i18n.getHelperMessage('items', 'status')"/>
@ -302,7 +302,7 @@
<div <div
class="column is-4-5" class="column is-4-5"
v-show="!isMetadataColumnCompressed"> v-show="!isMetadataColumnCompressed">
<label class="section-label">{{ $i18n.get('fields') }}</label> <label class="section-label">{{ $i18n.get('metadata') }}</label>
<br> <br>
<a <a
class="collapse-all" class="collapse-all"
@ -313,12 +313,12 @@
:icon=" collapseAll ? 'menu-down' : 'menu-right'" /> :icon=" collapseAll ? 'menu-down' : 'menu-right'" />
</a> </a>
<!-- Fields from Collection-------------------------------- --> <!-- Metadata from Collection-------------------------------- -->
<tainacan-form-item <tainacan-form-item
v-for="(field, index) of fieldList" v-for="(metadatum, index) of metadatumList"
:key="index" :key="index"
:field="field" :metadatum="metadatum"
:is-collapsed="fieldCollapses[index]" :is-collapsed="metadatumCollapses[index]"
@changeCollapse="onChangeCollapse($event, index)"/> @changeCollapse="onChangeCollapse($event, index)"/>
</div> </div>
@ -348,7 +348,7 @@ export default {
collectionId: Number, collectionId: Number,
isLoading: false, isLoading: false,
isMetadataColumnCompressed: false, isMetadataColumnCompressed: false,
fieldCollapses: [], metadatumCollapses: [],
collapseAll: false, collapseAll: false,
form: { form: {
collectionId: Number, collectionId: Number,
@ -383,8 +383,8 @@ export default {
} }
}, },
computed: { computed: {
fieldList() { metadatumList() {
return JSON.parse(JSON.stringify(this.getFields())); return JSON.parse(JSON.stringify(this.getMetadata()));
}, },
attachmentsList(){ attachmentsList(){
return this.getAttachments(); return this.getAttachments();
@ -398,16 +398,16 @@ export default {
'sendItem', 'sendItem',
'updateItem', 'updateItem',
'updateItemDocument', 'updateItemDocument',
'fetchFields', 'fetchMetadata',
'sendField', 'sendMetadatum',
'fetchItem', 'fetchItem',
'cleanFields', 'cleanMetadata',
'sendAttachments', 'sendAttachments',
'updateThumbnail', 'updateThumbnail',
'fetchAttachments' 'fetchAttachments'
]), ]),
...mapGetters('item',[ ...mapGetters('item',[
'getFields', 'getMetadata',
'getAttachments' 'getAttachments'
]), ]),
onSubmit() { onSubmit() {
@ -431,8 +431,8 @@ export default {
}) })
.catch((errors) => { .catch((errors) => {
for (let error of errors.errors) { for (let error of errors.errors) {
for (let field of Object.keys(error)){ for (let metadatum of Object.keys(error)){
eventBus.errors.push({ field_id: field, errors: error[field]}); eventBus.errors.push({ metadatum_id: metadatum, errors: error[metadatum]});
} }
} }
this.formErrorMessage = errors.error_message; this.formErrorMessage = errors.error_message;
@ -466,11 +466,11 @@ export default {
.catch(error => this.$console.error(error)); .catch(error => this.$console.error(error));
}, },
loadMetadata() { loadMetadata() {
// Obtains Item Field // Obtains Item Metadatum
this.fetchFields(this.itemId).then((fields) => { this.fetchMetadata(this.itemId).then((metadata) => {
this.isLoading = false; this.isLoading = false;
for (let field of fields) { for (let metadatum of metadata) {
this.fieldCollapses.push(field.field.required == 'yes'); this.metadatumCollapses.push(metadatum.metadatum.required == 'yes');
} }
}); });
}, },
@ -492,8 +492,8 @@ export default {
}) })
.catch((errors) => { .catch((errors) => {
for (let error of errors.errors) { for (let error of errors.errors) {
for (let field of Object.keys(error)){ for (let metadatum of Object.keys(error)){
eventBus.errors.push({ field_id: field, errors: error[field]}); eventBus.errors.push({ metadatum_id: metadatum, errors: error[metadatum]});
} }
} }
this.formErrorMessage = errors.error_message; this.formErrorMessage = errors.error_message;
@ -524,8 +524,8 @@ export default {
}) })
.catch((errors) => { .catch((errors) => {
for (let error of errors.errors) { for (let error of errors.errors) {
for (let field of Object.keys(error)){ for (let metadatum of Object.keys(error)){
eventBus.errors.push({ field_id: field, errors: error[field]}); eventBus.errors.push({ metadatum_id: metadatum, errors: error[metadatum]});
} }
} }
this.formErrorMessage = errors.error_message; this.formErrorMessage = errors.error_message;
@ -578,8 +578,8 @@ export default {
}) })
.catch((errors) => { .catch((errors) => {
for (let error of errors.errors) { for (let error of errors.errors) {
for (let field of Object.keys(error)){ for (let metadatum of Object.keys(error)){
eventBus.errors.push({ field_id: field, errors: error[field]}); eventBus.errors.push({ metadatum_id: metadatum, errors: error[metadatum]});
} }
} }
this.formErrorMessage = errors.error_message; this.formErrorMessage = errors.error_message;
@ -623,17 +623,17 @@ export default {
toggleCollapseAll() { toggleCollapseAll() {
this.collapseAll = !this.collapseAll; this.collapseAll = !this.collapseAll;
for (let i = 0; i < this.fieldCollapses.length; i++) for (let i = 0; i < this.metadatumCollapses.length; i++)
this.fieldCollapses[i] = this.collapseAll; this.metadatumCollapses[i] = this.collapseAll;
}, },
onChangeCollapse(event, index) { onChangeCollapse(event, index) {
this.fieldCollapses.splice(index, 1, event); this.metadatumCollapses.splice(index, 1, event);
} }
}, },
created(){ created(){
// Obtains collection ID // Obtains collection ID
this.cleanFields(); this.cleanMetadata();
eventBus.clearAllErrors(); eventBus.clearAllErrors();
this.formErrorMessage = ''; this.formErrorMessage = '';
this.collectionId = this.$route.params.collectionId; this.collectionId = this.$route.params.collectionId;
@ -745,7 +745,7 @@ export default {
padding-right: $page-side-padding; padding-right: $page-side-padding;
transition: all 0.6s; transition: all 0.6s;
.field { .metadatum {
padding: 10px 0px 10px 25px; padding: 10px 0px 10px 25px;
} }

View File

@ -1,6 +1,6 @@
<template> <template>
<form <form
id="fieldEditForm" id="metadatumEditForm"
class="tainacan-form" class="tainacan-form"
@submit.prevent="saveEdition(editForm)"> @submit.prevent="saveEdition(editForm)">
@ -11,11 +11,11 @@
<label class="label is-inline"> <label class="label is-inline">
{{ $i18n.get('label_name') }} {{ $i18n.get('label_name') }}
<span <span
class="required-field-asterisk" class="required-metadatum-asterisk"
:class="formErrors['name'] != undefined ? 'is-danger' : ''">*</span> :class="formErrors['name'] != undefined ? 'is-danger' : ''">*</span>
<help-button <help-button
:title="$i18n.getHelperTitle('fields', 'name')" :title="$i18n.getHelperTitle('metadata', 'name')"
:message="$i18n.getHelperMessage('fields', 'name')"/> :message="$i18n.getHelperMessage('metadata', 'name')"/>
</label> </label>
<b-input <b-input
:class="{'has-content': editForm.name != undefined && editForm.name != ''}" :class="{'has-content': editForm.name != undefined && editForm.name != ''}"
@ -31,8 +31,8 @@
<label class="label is-inline"> <label class="label is-inline">
{{ $i18n.get('label_description') }} {{ $i18n.get('label_description') }}
<help-button <help-button
:title="$i18n.getHelperTitle('fields', 'description')" :title="$i18n.getHelperTitle('metadata', 'description')"
:message="$i18n.getHelperMessage('fields', 'description')"/> :message="$i18n.getHelperMessage('metadata', 'description')"/>
</label> </label>
<b-input <b-input
:class="{'has-content': editForm.description != undefined && editForm.description != ''}" :class="{'has-content': editForm.description != undefined && editForm.description != ''}"
@ -49,8 +49,8 @@
<label class="label is-inline"> <label class="label is-inline">
{{ $i18n.get('label_status') }} {{ $i18n.get('label_status') }}
<help-button <help-button
:title="$i18n.getHelperTitle('fields', 'status')" :title="$i18n.getHelperTitle('metadata', 'status')"
:message="$i18n.getHelperMessage('fields', 'status')"/> :message="$i18n.getHelperMessage('metadata', 'status')"/>
</label> </label>
<b-field> <b-field>
<b-radio <b-radio
@ -84,8 +84,8 @@
<label class="label is-inline"> <label class="label is-inline">
{{ $i18n.get('label_display') }} {{ $i18n.get('label_display') }}
<help-button <help-button
:title="$i18n.getHelperTitle('fields', 'display')" :title="$i18n.getHelperTitle('metadata', 'display')"
:message="$i18n.getHelperMessage('fields', 'display')"/> :message="$i18n.getHelperMessage('metadata', 'display')"/>
</label> </label>
@ -139,13 +139,13 @@
name="required"> name="required">
{{ $i18n.get('label_required') }} {{ $i18n.get('label_required') }}
<help-button <help-button
:title="$i18n.getHelperTitle('fields', 'required')" :title="$i18n.getHelperTitle('metadata', 'required')"
:message="$i18n.getHelperMessage('fields', 'required')"/> :message="$i18n.getHelperMessage('metadata', 'required')"/>
</b-checkbox> </b-checkbox>
</b-field> </b-field>
<b-field <b-field
v-if="!originalField.field_type_object.core" v-if="!originalMetadatum.metadatum_type_object.core"
:type="formErrors['multiple'] != undefined ? 'is-danger' : ''" :type="formErrors['multiple'] != undefined ? 'is-danger' : ''"
:message="formErrors['multiple'] != undefined ? formErrors['multiple'] : ''"> :message="formErrors['multiple'] != undefined ? formErrors['multiple'] : ''">
<b-checkbox <b-checkbox
@ -158,8 +158,8 @@
name="multiple"> name="multiple">
{{ $i18n.get('label_allow_multiple') }} {{ $i18n.get('label_allow_multiple') }}
<help-button <help-button
:title="$i18n.getHelperTitle('fields', 'multiple')" :title="$i18n.getHelperTitle('metadata', 'multiple')"
:message="$i18n.getHelperMessage('fields', 'multiple')"/> :message="$i18n.getHelperMessage('metadata', 'multiple')"/>
</b-checkbox> </b-checkbox>
</b-field> </b-field>
@ -176,18 +176,18 @@
name="collecion_key"> name="collecion_key">
{{ $i18n.get('label_unique_value') }} {{ $i18n.get('label_unique_value') }}
<help-button <help-button
:title="$i18n.getHelperTitle('fields', 'unique')" :title="$i18n.getHelperTitle('metadata', 'unique')"
:message="$i18n.getHelperMessage('fields', 'unique')"/> :message="$i18n.getHelperMessage('metadata', 'unique')"/>
</b-checkbox> </b-checkbox>
</b-field> </b-field>
</b-field> </b-field>
<component <component
:errors="formErrors['field_type_options']" :errors="formErrors['metadatum_type_options']"
v-if="(editForm.field_type_object && editForm.field_type_object.form_component) || editForm.edit_form == ''" v-if="(editForm.metadatum_type_object && editForm.metadatum_type_object.form_component) || editForm.edit_form == ''"
:is="editForm.field_type_object.form_component" :is="editForm.metadatum_type_object.form_component"
:field="editForm" :metadatum="editForm"
v-model="editForm.field_type_options"/> v-model="editForm.metadatum_type_options"/>
<div <div
v-html="editForm.edit_form" v-html="editForm.edit_form"
v-else/> v-else/>
@ -216,7 +216,7 @@
import {mapActions} from 'vuex'; import {mapActions} from 'vuex';
export default { export default {
name: 'FieldEditionForm', name: 'MetadatumEditionForm',
data() { data() {
return { return {
editForm: {}, editForm: {},
@ -228,42 +228,42 @@
}, },
props: { props: {
index: '', index: '',
editedField: Object, editedMetadatum: Object,
originalField: Object, originalMetadatum: Object,
isRepositoryLevel: false, isRepositoryLevel: false,
collectionId: '' collectionId: ''
}, },
created() { created() {
this.editForm = this.editedField; this.editForm = this.editedMetadatum;
this.formErrors = this.editForm.formErrors != undefined ? this.editForm.formErrors : {}; this.formErrors = this.editForm.formErrors != undefined ? this.editForm.formErrors : {};
this.formErrorMessage = this.editForm.formErrors != undefined ? this.editForm.formErrorMessage : ''; 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() { beforeDestroy() {
if (this.closedByForm) { if (this.closedByForm) {
this.editedField.saved = true; this.editedMetadatum.saved = true;
} else { } else {
this.oldForm.saved = this.editForm.saved; this.oldForm.saved = this.editForm.saved;
if (JSON.stringify(this.editForm) != JSON.stringify(this.oldForm)) if (JSON.stringify(this.editForm) != JSON.stringify(this.oldForm))
this.editedField.saved = false; this.editedMetadatum.saved = false;
else else
this.editedField.saved = true; this.editedMetadatum.saved = true;
} }
}, },
methods: { methods: {
...mapActions('fields', [ ...mapActions('metadata', [
'updateField' '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, collectionId: this.collectionId,
fieldId: field.id, metadatumId: metadatum.id,
isRepositoryLevel: this.isRepositoryLevel, isRepositoryLevel: this.isRepositoryLevel,
index: this.index, index: this.index,
options: this.editForm options: this.editForm
@ -287,16 +287,16 @@
this.editForm.formErrorMessage = this.formErrorMessage; this.editForm.formErrorMessage = this.formErrorMessage;
}); });
} else { } else {
let formElement = document.getElementById('fieldEditForm'); let formElement = document.getElementById('metadatumEditForm');
let formData = new FormData(formElement); let formData = new FormData(formElement);
let formObj = {}; let formObj = {};
for (let [key, value] of formData.entries()) for (let [key, value] of formData.entries())
formObj[key] = value; formObj[key] = value;
this.updateField({ this.updateMetadatum({
collectionId: this.collectionId, collectionId: this.collectionId,
fieldId: field.id, metadatumId: metadatum.id,
isRepositoryLevel: this.isRepositoryLevel, isRepositoryLevel: this.isRepositoryLevel,
index: this.index, index: this.index,
options: formObj options: formObj

View File

@ -150,8 +150,8 @@
}) })
.catch((errors) => { .catch((errors) => {
for (let error of errors.errors) { for (let error of errors.errors) {
for (let field of Object.keys(error)) { for (let metadatum of Object.keys(error)) {
this.$set(this.formErrors, field, (this.formErrors[field] !== undefined ? this.formErrors[field] : '') + error[field] + '\n'); this.$set(this.formErrors, metadatum, (this.formErrors[metadatum] !== undefined ? this.formErrors[metadatum] : '') + error[metadatum] + '\n');
} }
} }
this.$emit('onErrorFound'); this.$emit('onErrorFound');
@ -173,8 +173,8 @@
}) })
.catch((errors) => { .catch((errors) => {
for (let error of errors.errors) { for (let error of errors.errors) {
for (let field of Object.keys(error)) { for (let metadatum of Object.keys(error)) {
this.$set(this.formErrors, field, (this.formErrors[field] !== undefined ? this.formErrors[field] : '') + error[field] + '\n'); this.$set(this.formErrors, metadatum, (this.formErrors[metadatum] !== undefined ? this.formErrors[metadatum] : '') + error[metadatum] + '\n');
} }
} }
this.$emit('onErrorFound'); this.$emit('onErrorFound');

View File

@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<b-loading :active.sync="isLoadingFieldTypes"/> <b-loading :active.sync="isLoadingMetadatumTypes"/>
<tainacan-title v-if="!isRepositoryLevel"/> <tainacan-title v-if="!isRepositoryLevel"/>
<p v-if="isRepositoryLevel">{{ $i18n.get('info_repository_filters_inheritance') }}</p> <p v-if="isRepositoryLevel">{{ $i18n.get('info_repository_filters_inheritance') }}</p>
<br> <br>
@ -35,7 +35,7 @@
<div <div
class="active-filter-item" class="active-filter-item"
:class="{ :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, 'not-focusable-item': openedFilterId == filter.id,
'disabled-filter': filter.enabled == false 'disabled-filter': filter.enabled == false
}" }"
@ -84,7 +84,7 @@
</a> </a>
</span> </span>
</div> </div>
<div v-if="choosenField.id == filter.id && openedFilterId == ''"> <div v-if="choosenMetadatum.id == filter.id && openedFilterId == ''">
<form class="tainacan-form"> <form class="tainacan-form">
<b-field :label="$i18n.get('label_filter_type')"> <b-field :label="$i18n.get('label_filter_type')">
<b-select <b-select
@ -128,25 +128,25 @@
</div> </div>
</draggable> </draggable>
</div> </div>
<div class="column available-fields-area"> <div class="column available-metadata-area">
<div class="field" > <div class="field" >
<h3 class="label"> {{ $i18n.get('label_available_fields') }}</h3> <h3 class="label"> {{ $i18n.get('label_available_metadata') }}</h3>
<draggable <draggable
v-if="availableFieldList.length > 0" v-if="availableMetadatumList.length > 0"
v-model="availableFieldList" v-model="availableMetadatumList"
:options="{ :options="{
sort: false, sort: false,
group: { name:'filters', pull: true, put: false, revertClone: true }, group: { name:'filters', pull: true, put: false, revertClone: true },
dragClass: 'sortable-drag' dragClass: 'sortable-drag'
}"> }">
<div <div
class="available-field-item" class="available-metadatum-item"
v-if="field.enabled" v-if="metadatum.enabled"
v-for="(field, index) in availableFieldList" v-for="(metadatum, index) in availableMetadatumList"
:key="index" :key="index"
@click.prevent="addFieldViaButton(field, index)"> @click.prevent="addMetadatumViaButton(metadatum, index)">
<grip-icon/> <grip-icon/>
<span class="field-name">{{ field.name }}</span> <span class="metadatum-name">{{ metadatum.name }}</span>
</div> </div>
</draggable> </draggable>
@ -159,13 +159,13 @@
icon="format-list-checks" icon="format-list-checks"
size="is-large"/> size="is-large"/>
</p> </p>
<p>{{ $i18n.get('info_there_is_no_field' ) }}</p> <p>{{ $i18n.get('info_there_is_no_metadatum' ) }}</p>
<router-link <router-link
id="button-create-field" id="button-create-metadatum"
:to="isRepositoryLevel ? $routerHelper.getNewFieldPath() : $routerHelper.getNewCollectionFieldPath(collectionId)" :to="isRepositoryLevel ? $routerHelper.getNewMetadatumPath() : $routerHelper.getNewCollectionMetadatumPath(collectionId)"
tag="button" tag="button"
class="button is-secondary is-centered"> class="button is-secondary is-centered">
{{ $i18n.getFrom('fields', 'new_item') }}</router-link> {{ $i18n.getFrom('metadata', 'new_item') }}</router-link>
</div> </div>
</section> </section>
</div> </div>
@ -187,7 +187,7 @@ export default {
collectionId: '', collectionId: '',
isRepositoryLevel: false, isRepositoryLevel: false,
isDraggingFromAvailable: false, isDraggingFromAvailable: false,
isLoadingFieldTypes: true, isLoadingMetadatumTypes: true,
isLoadingFilters: false, isLoadingFilters: false,
isLoadingFilterTypes: false, isLoadingFilterTypes: false,
isLoadingFilter: false, isLoadingFilter: false,
@ -196,9 +196,9 @@ export default {
editForms: {}, editForms: {},
allowedFilterTypes: [], allowedFilterTypes: [],
selectedFilterType: {}, selectedFilterType: {},
choosenField: {}, choosenMetadatum: {},
newIndex: 0, newIndex: 0,
availableFieldList: [], availableMetadatumList: [],
filterTypes: [] filterTypes: []
} }
}, },
@ -255,11 +255,11 @@ export default {
'getFilters', 'getFilters',
'getFilterTypes' 'getFilterTypes'
]), ]),
...mapActions('fields', [ ...mapActions('metadata', [
'fetchFields', 'fetchMetadata',
]), ]),
...mapGetters('fields', [ ...mapGetters('metadata', [
'getFields', 'getMetadata',
]), ]),
handleChange($event) { handleChange($event) {
if ($event.added) { if ($event.added) {
@ -278,20 +278,20 @@ export default {
} }
this.updateCollectionFiltersOrder({ collectionId: this.collectionId, filtersOrder: filtersOrder }); 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 activeFilter of this.activeFilterList) {
for (let i = availableFields.length - 1; i >= 0 ; i--) { for (let i = availableMetadata.length - 1; i >= 0 ; i--) {
if (activeFilter.field != undefined) { if (activeFilter.metadatum != undefined) {
if (activeFilter.field.field_id == availableFields[i].id) if (activeFilter.metadatum.metadatum_id == availableMetadata[i].id)
availableFields.splice(i, 1); availableMetadata.splice(i, 1);
} }
} }
} }
this.availableFieldList = availableFields; this.availableMetadatumList = availableMetadata;
}, },
onChangeEnable($event, index) { onChangeEnable($event, index) {
this.activeFilterList[index].enabled = $event; this.activeFilterList[index].enabled = $event;
@ -301,17 +301,17 @@ export default {
} }
this.updateCollectionFiltersOrder({ collectionId: this.collectionId, filtersOrder: filtersOrder }); this.updateCollectionFiltersOrder({ collectionId: this.collectionId, filtersOrder: filtersOrder });
}, },
addFieldViaButton(fieldType, fieldIndex) { addMetadatumViaButton(metadatumType, metadatumIndex) {
this.availableFieldList.splice(fieldIndex, 1); this.availableMetadatumList.splice(metadatumIndex, 1);
let lastIndex = this.activeFilterList.length; let lastIndex = this.activeFilterList.length;
// Updates store with temporary Filter // Updates store with temporary Filter
this.addTemporaryFilter(fieldType); this.addTemporaryFilter(metadatumType);
this.addNewFilter(fieldType, lastIndex); this.addNewFilter(metadatumType, lastIndex);
}, },
addNewFilter(choosenField, newIndex) { addNewFilter(choosenMetadatum, newIndex) {
this.choosenField = choosenField; this.choosenMetadatum = choosenMetadatum;
this.newIndex = newIndex; this.newIndex = newIndex;
this.openedFilterId = ''; this.openedFilterId = '';
this.allowedFilterTypes = []; this.allowedFilterTypes = [];
@ -319,7 +319,7 @@ export default {
for (let filter of this.filterTypes) { for (let filter of this.filterTypes) {
for (let supportedType of filter['supported_types']) { 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); this.allowedFilterTypes.push(filter);
} }
} }
@ -328,8 +328,8 @@ export default {
this.sendFilter({ this.sendFilter({
collectionId: this.collectionId, collectionId: this.collectionId,
fieldId: this.choosenField.id, metadatumId: this.choosenMetadatum.id,
name: this.choosenField.name, name: this.choosenMetadatum.name,
filterType: this.selectedFilterType.name, filterType: this.selectedFilterType.name,
status: 'auto-draft', status: 'auto-draft',
isRepositoryLevel: this.isRepositoryLevel, isRepositoryLevel: this.isRepositoryLevel,
@ -341,7 +341,7 @@ export default {
this.updateFiltersOrder(); this.updateFiltersOrder();
this.newIndex = 0; this.newIndex = 0;
this.choosenField = {}; this.choosenMetadatum = {};
this.selectedFilterType = {} this.selectedFilterType = {}
this.allowedFilterTypes = []; this.allowedFilterTypes = [];
@ -350,7 +350,7 @@ export default {
.catch((error) => { .catch((error) => {
this.$console.error(error); this.$console.error(error);
this.newIndex = 0; this.newIndex = 0;
this.choosenField = {}; this.choosenMetadatum = {};
this.selectedFilterType = {} this.selectedFilterType = {}
this.allowedFilterTypes = []; this.allowedFilterTypes = [];
}); });
@ -359,8 +359,8 @@ export default {
this.deleteFilter(removedFilter.id) this.deleteFilter(removedFilter.id)
.then(() => { .then(() => {
// Reload Available Field Types List // Reload Available Metadatum Types List
this.updateListOfFields(); this.updateListOfMetadata();
}) })
.catch((error) => { this.$console.log(error)}); .catch((error) => { this.$console.log(error)});
@ -372,8 +372,8 @@ export default {
this.createChoosenFilter(); this.createChoosenFilter();
}, },
cancelFilterTypeSelection() { cancelFilterTypeSelection() {
this.availableFieldList.push(this.choosenField); this.availableMetadatumList.push(this.choosenMetadatum);
this.choosenField = {}; this.choosenMetadatum = {};
this.allowedFilterTypes = []; this.allowedFilterTypes = [];
this.selectedFilterType = {}; this.selectedFilterType = {};
this.deleteTemporaryFilter(this.newIndex); this.deleteTemporaryFilter(this.newIndex);
@ -387,9 +387,9 @@ export default {
// Opening collapse // Opening collapse
} else { } else {
if (this.openedFilterId == '' && this.choosenField.id != undefined) { if (this.openedFilterId == '' && this.choosenMetadatum.id != undefined) {
this.availableFieldList.push(this.choosenField); this.availableMetadatumList.push(this.choosenMetadatum);
this.choosenField = {}; this.choosenMetadatum = {};
this.allowedFilterTypes = []; this.allowedFilterTypes = [];
this.selectedFilterType = {}; this.selectedFilterType = {};
this.deleteTemporaryFilter(this.newIndex); this.deleteTemporaryFilter(this.newIndex);
@ -429,7 +429,7 @@ export default {
else else
this.collectionId = this.$route.params.collectionId; this.collectionId = this.$route.params.collectionId;
this.isLoadingFieldTypes = true; this.isLoadingMetadatumTypes = true;
this.isLoadingFilters = true; this.isLoadingFilters = true;
this.isLoadingFilterTypes = true; this.isLoadingFilterTypes = true;
@ -445,14 +445,14 @@ export default {
this.fetchFilters({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true, includeDisabled: 'yes' }) this.fetchFilters({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true, includeDisabled: 'yes' })
.then(() => { .then(() => {
this.isLoadingFilters = false; this.isLoadingFilters = false;
// Needs to be done after activeFilterList exists to compare and remove chosen fields. // Needs to be done after activeFilterList exists to compare and remove chosen metadata.
this.fetchFields({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true }) this.fetchMetadata({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true })
.then(() => { .then(() => {
this.isLoadingFieldTypes = false; this.isLoadingMetadatumTypes = false;
this.updateListOfFields(); this.updateListOfMetadata();
}) })
.catch(() => { .catch(() => {
this.isLoadingFieldTypes = false; this.isLoadingMetadatumTypes = false;
}); });
}) })
.catch(() => { .catch(() => {
@ -589,14 +589,14 @@ export default {
&.not-focusable-item, &.not-focusable-item:hover { &.not-focusable-item, &.not-focusable-item:hover {
cursor: default; cursor: default;
.field-name { .metadatum-name {
color: $secondary; color: $secondary;
} }
.handle .label-details, .handle .icon { .handle .label-details, .handle .icon {
color: $gray !important; color: $gray !important;
} }
} }
&.disabled-field { &.disabled-metadatum {
color: $gray; color: $gray;
} }
} }
@ -645,7 +645,7 @@ export default {
} }
} }
.available-fields-area { .available-metadata-area {
padding: 10px 0px 10px 10px; padding: 10px 0px 10px 10px;
margin: 0; margin: 0;
max-width: 280px; max-width: 280px;
@ -657,8 +657,8 @@ export default {
h3 { h3 {
margin: 1em 0em 1em 0em !important; margin: 1em 0em 1em 0em !important;
} }
.available-field-item::before, .available-metadatum-item::before,
.available-field-item::after { .available-metadatum-item::after {
display: none !important; display: none !important;
} }
} }
@ -669,7 +669,7 @@ export default {
font-weight: 500; font-weight: 500;
} }
.available-field-item { .available-metadatum-item {
padding: 0.7em; padding: 0.7em;
margin: 4px; margin: 4px;
background-color: white; background-color: white;
@ -692,7 +692,7 @@ export default {
position: relative; position: relative;
bottom: 3px; bottom: 3px;
} }
.field-name { .metadatum-name {
text-overflow: ellipsis; text-overflow: ellipsis;
overflow-x: hidden; overflow-x: hidden;
white-space: nowrap; white-space: nowrap;
@ -731,7 +731,7 @@ export default {
.sortable-drag { .sortable-drag {
opacity: 1 !important; opacity: 1 !important;
} }
.available-field-item:hover { .available-metadatum-item:hover {
background-color: $secondary; background-color: $secondary;
border-color: $secondary; border-color: $secondary;
color: white; color: white;

View File

@ -57,9 +57,9 @@
<!-- Title --> <!-- Title -->
<p <p
v-for="(column, index) in tableFields" v-for="(column, index) in tableMetadata"
:key="index" :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" class="metadata-title"
@click="goToItemPage(item)" @click="goToItemPage(item)"
v-html="item.metadata != undefined ? renderMetadata(item.metadata, column) : ''"/> v-html="item.metadata != undefined ? renderMetadata(item.metadata, column) : ''"/>
@ -118,9 +118,9 @@
<!-- Title --> <!-- Title -->
<p <p
v-for="(column, index) in tableFields" v-for="(column, index) in tableMetadata"
:key="index" :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" class="metadata-title"
@click="goToItemPage(item)" @click="goToItemPage(item)"
v-html="item.metadata != undefined ? renderMetadata(item.metadata, column) : ''" /> v-html="item.metadata != undefined ? renderMetadata(item.metadata, column) : ''" />
@ -160,9 +160,9 @@
<div class="list-metadata media-body"> <div class="list-metadata media-body">
<span <span
v-for="(column, index) in tableFields" v-for="(column, index) in tableMetadata"
:key="index" :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> <h3 class="metadata-label">{{ column.name }}</h3>
<p <p
v-html="item.metadata != undefined ? renderMetadata(item.metadata, column) : ''" v-html="item.metadata != undefined ? renderMetadata(item.metadata, column) : ''"
@ -185,17 +185,17 @@
&nbsp; &nbsp;
<!-- nothing to show on header for checkboxes --> <!-- nothing to show on header for checkboxes -->
</th> </th>
<!-- Displayed Fields --> <!-- Displayed Metadata -->
<th <th
v-for="(column, index) in tableFields" v-for="(column, index) in tableMetadata"
:key="index" :key="index"
v-if="column.display" v-if="column.display"
class="column-default-width" class="column-default-width"
:class="{ :class="{
'thumbnail-cell': column.field == 'row_thumbnail', 'thumbnail-cell': column.metadatum == '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-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.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-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.field_type_object != undefined ? (column.field_type_object.className == 'Tainacan\\Field_Types\\Textarea') : false, 'column-large-width' : column.metadatum_type_object != undefined ? (column.metadatum_type_object.className == 'Tainacan\\Metadatum_Types\\Textarea') : false,
}" }"
:custom-key="column.slug"> :custom-key="column.slug">
<div class="th-wrap">{{ column.name }}</div> <div class="th-wrap">{{ column.name }}</div>
@ -223,24 +223,24 @@
<!-- Item Displayed Metadata --> <!-- Item Displayed Metadata -->
<td <td
:key="index" :key="index"
v-for="(column, index) in tableFields" v-for="(column, index) in tableMetadata"
v-if="column.display" v-if="column.display"
:label="column.name" :label="column.name"
class="column-default-width" class="column-default-width"
:class="{ :class="{
'thumbnail-cell': column.field == 'row_thumbnail', 'thumbnail-cell': column.metadatum == 'row_thumbnail',
'column-main-content' : column.field_type_object != undefined ? (column.field_type_object.related_mapped_prop == 'title') : false, 'column-main-content' : column.metadatum_type_object != undefined ? (column.metadatum_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-needed-width column-align-right' : column.metadatum_type_object != undefined ? (column.metadatum_type_object.className == 'Tainacan\\Metadatum_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-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.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-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.field_type_object != undefined ? (column.field_type_object.className == 'Tainacan\\Field_Types\\Textarea') : false, 'column-large-width' : column.metadatum_type_object != undefined ? (column.metadatum_type_object.className == 'Tainacan\\Metadatum_Types\\Textarea') : false,
}" }"
@click="goToItemPage(item)"> @click="goToItemPage(item)">
<!-- <data-and-tooltip <!-- <data-and-tooltip
v-if="column.field !== 'row_thumbnail' && v-if="column.metadatum !== 'row_thumbnail' &&
column.field !== 'row_actions' && column.metadatum !== 'row_actions' &&
column.field !== 'row_creation'" column.metadatum !== 'row_creation'"
:data="renderMetadata(item.metadata, column)"/> --> :data="renderMetadata(item.metadata, column)"/> -->
<p <p
v-tooltip="{ v-tooltip="{
@ -250,13 +250,13 @@
placement: 'auto-start' placement: 'auto-start'
}" }"
v-if="item.metadata != undefined && v-if="item.metadata != undefined &&
column.field !== 'row_thumbnail' && column.metadatum !== 'row_thumbnail' &&
column.field !== 'row_actions' && column.metadatum !== 'row_actions' &&
column.field !== 'row_creation' && column.metadatum !== 'row_creation' &&
column.field !== 'row_author'" column.metadatum !== 'row_author'"
v-html="renderMetadata(item.metadata, column)"/> v-html="renderMetadata(item.metadata, column)"/>
<span v-if="column.field == 'row_thumbnail'"> <span v-if="column.metadatum == 'row_thumbnail'">
<img <img
class="table-thumb" class="table-thumb"
:src="item['thumbnail'].thumb ? item['thumbnail'].thumb : thumbPlaceholderPath"> :src="item['thumbnail'].thumb ? item['thumbnail'].thumb : thumbPlaceholderPath">
@ -268,7 +268,7 @@
autoHide: false, autoHide: false,
placement: 'auto-start' 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] }} {{ item[column.slug] }}
</p> </p>
@ -321,7 +321,7 @@ export default {
}, },
props: { props: {
collectionId: Number, collectionId: Number,
tableFields: Array, tableMetadata: Array,
items: Array, items: Array,
isLoading: false, isLoading: false,
isOnTrash: false, isOnTrash: false,

View File

@ -1,15 +1,15 @@
<template> <template>
<div> <div>
<b-loading :active.sync="isLoadingFieldTypes"/> <b-loading :active.sync="isLoadingMetadatumTypes"/>
<tainacan-title v-if="!isRepositoryLevel"/> <tainacan-title v-if="!isRepositoryLevel"/>
<p v-if="isRepositoryLevel">{{ $i18n.get('info_repository_metadata_inheritance') }}</p> <p v-if="isRepositoryLevel">{{ $i18n.get('info_repository_metadata_inheritance') }}</p>
<br> <br>
<b-tabs v-model="activeTab"> <b-tabs v-model="activeTab">
<b-tab-item :label="$i18n.get('fields')"> <b-tab-item :label="$i18n.get('metadata')">
<div class="columns"> <div class="columns">
<div class="column"> <div class="column">
<section <section
v-if="activeFieldList.length <= 0 && !isLoadingFields" v-if="activeMetadatumList.length <= 0 && !isLoadingMetadata"
class="field is-grouped-centered section"> class="field is-grouped-centered section">
<div class="content has-text-gray has-text-centered"> <div class="content has-text-gray has-text-centered">
<p> <p>
@ -17,120 +17,120 @@
icon="format-list-bulleted-type" icon="format-list-bulleted-type"
size="is-large"/> size="is-large"/>
</p> </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> <p>{{ $i18n.get('info_create_metadata' ) }}</p>
</div> </div>
</section> </section>
<draggable <draggable
v-model="activeFieldList" v-model="activeMetadatumList"
class="active-fields-area" class="active-metadata-area"
@change="handleChange" @change="handleChange"
:class="{'fields-area-receive': isDraggingFromAvailable}" :class="{'metadata-area-receive': isDraggingFromAvailable}"
:options="{ :options="{
group: { name:'fields', pull: false, put: true }, group: { name:'metadata', pull: false, put: true },
sort: openedFieldId == '' || openedFieldId == undefined, sort: openedMetadatumId == '' || openedMetadatumId == undefined,
//disabled: openedFieldId != '' && openedFieldId != undefined, //disabled: openedMetadatumId != '' && openedMetadatumId != undefined,
handle: '.handle', handle: '.handle',
ghostClass: 'sortable-ghost', ghostClass: 'sortable-ghost',
chosenClass: 'sortable-chosen', chosenClass: 'sortable-chosen',
filter: 'not-sortable-item', filter: 'not-sortable-item',
animation: '250'}"> animation: '250'}">
<div <div
class="active-field-item" class="active-metadatum-item"
:class="{ :class="{
'not-sortable-item': field.id == undefined || openedFieldId != '' , 'not-sortable-item': metadatum.id == undefined || openedMetadatumId != '' ,
'not-focusable-item': openedFieldId == field.id, 'not-focusable-item': openedMetadatumId == metadatum.id,
'disabled-field': field.enabled == false 'disabled-metadatum': metadatum.enabled == false
}" }"
v-for="(field, index) in activeFieldList" v-for="(metadatum, index) in activeMetadatumList"
:key="index"> :key="index">
<div class="handle"> <div class="handle">
<grip-icon/> <grip-icon/>
<span <span
class="field-name" class="metadatum-name"
:class="{'is-danger': formWithErrors == field.id }"> :class="{'is-danger': formWithErrors == metadatum.id }">
{{ field.name }} {{ metadatum.name }}
</span> </span>
<span <span
v-if="field.id != undefined" v-if="metadatum.id != undefined"
class="label-details"> 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 <span
class="not-saved" 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') }} {{ $i18n.get('info_not_saved') }}
</span> </span>
</span> </span>
<span <span
class="loading-spinner" class="loading-spinner"
v-if="field.id == undefined"/> v-if="metadatum.id == undefined"/>
<span <span
class="controls" class="controls"
v-if="field.id !== undefined"> v-if="metadatum.id !== undefined">
<b-switch <b-switch
size="is-small" size="is-small"
v-model="field.enabled" v-model="metadatum.enabled"
@input="onChangeEnable($event, index)"/> @input="onChangeEnable($event, index)"/>
<a <a
:style="{ visibility: :style="{ visibility:
field.collection_id != collectionId metadatum.collection_id != collectionId
? 'hidden' : 'visible' ? 'hidden' : 'visible'
}" }"
@click.prevent="editField(field)"> @click.prevent="editMetadatum(metadatum)">
<b-icon <b-icon
type="is-gray" type="is-gray"
icon="pencil"/> icon="pencil"/>
</a> </a>
<a <a
:style="{ visibility: :style="{ visibility:
field.collection_id != collectionId || metadatum.collection_id != collectionId ||
field.field_type == 'Tainacan\\Field_Types\\Core_Title' || metadatum.metadatum_type == 'Tainacan\\Metadatum_Types\\Core_Title' ||
field.field_type == 'Tainacan\\Field_Types\\Core_Description' metadatum.metadatum_type == 'Tainacan\\Metadatum_Types\\Core_Description'
? 'hidden' : 'visible' ? 'hidden' : 'visible'
}" }"
@click.prevent="removeField(field)"> @click.prevent="removeMetadatum(metadatum)">
<b-icon <b-icon
type="is-gray" type="is-gray"
icon="delete"/> icon="delete"/>
</a> </a>
</span> </span>
</div> </div>
<div v-if="openedFieldId == field.id"> <div v-if="openedMetadatumId == metadatum.id">
<field-edition-form <metadatum-edition-form
:collection-id="collectionId" :collection-id="collectionId"
:is-repository-level="isRepositoryLevel" :is-repository-level="isRepositoryLevel"
@onEditionFinished="onEditionFinished()" @onEditionFinished="onEditionFinished()"
@onEditionCanceled="onEditionCanceled()" @onEditionCanceled="onEditionCanceled()"
@onErrorFound="formWithErrors = field.id" @onErrorFound="formWithErrors = metadatum.id"
:index="index" :index="index"
:original-field="field" :original-metadatum="metadatum"
:edited-field="editForms[field.id]"/> :edited-metadatum="editForms[metadatum.id]"/>
</div> </div>
</div> </div>
</draggable> </draggable>
</div> </div>
<div class="column available-fields-area" > <div class="column available-metadata-area" >
<div class="field"> <div class="field">
<h3 class="label">{{ $i18n.get('label_available_field_types') }}</h3> <h3 class="label">{{ $i18n.get('label_available_metadatum_types') }}</h3>
<draggable <draggable
v-model="availableFieldList" v-model="availableMetadatumList"
:options="{ :options="{
sort: false, sort: false,
group: { name:'fields', pull: 'clone', put: false, revertClone: true }, group: { name:'metadata', pull: 'clone', put: false, revertClone: true },
dragClass: 'sortable-drag' dragClass: 'sortable-drag'
}"> }">
<div <div
@click.prevent="addFieldViaButton(field)" @click.prevent="addMetadatumViaButton(metadatum)"
class="available-field-item" class="available-metadatum-item"
:class="{ 'hightlighted-field' : hightlightedField == field.name }" :class="{ 'hightlighted-metadatum' : hightlightedMetadatum == metadatum.name }"
v-for="(field, index) in availableFieldList" v-for="(metadatum, index) in availableMetadatumList"
:key="index"> :key="index">
<grip-icon/> <grip-icon/>
<span class="field-name">{{ field.name }}</span> <span class="metadatum-name">{{ metadatum.name }}</span>
<span <span
class="loading-spinner" class="loading-spinner"
v-if="hightlightedField == field.name"/> v-if="hightlightedMetadatum == metadatum.name"/>
</div> </div>
</draggable> </draggable>
</div> </div>
@ -148,44 +148,44 @@
<script> <script>
import { mapActions, mapGetters } from 'vuex'; import { mapActions, mapGetters } from 'vuex';
import GripIcon from '../other/grip-icon.vue'; 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'; import CustomDialog from '../other/custom-dialog.vue';
export default { export default {
name: 'FieldsList', name: 'MetadataList',
data(){ data(){
return { return {
collectionId: '', collectionId: '',
isRepositoryLevel: false, isRepositoryLevel: false,
isDraggingFromAvailable: false, isDraggingFromAvailable: false,
isLoadingFieldTypes: true, isLoadingMetadatumTypes: true,
isLoadingFields: false, isLoadingMetadata: false,
isLoadingField: false, isLoadingMetadatum: false,
openedFieldId: '', openedMetadatumId: '',
formWithErrors: '', formWithErrors: '',
hightlightedField: '', hightlightedMetadatum: '',
editForms: {} editForms: {}
} }
}, },
components: { components: {
FieldEditionForm, MetadatumEditionForm,
GripIcon GripIcon
}, },
computed: { computed: {
availableFieldList: { availableMetadatumList: {
get() { get() {
return this.getFieldTypes(); return this.getMetadatumTypes();
}, },
set(value) { set(value) {
return this.updateFieldTypes(value); return this.updateMetadatumTypes(value);
} }
}, },
activeFieldList: { activeMetadatumList: {
get() { get() {
return this.getFields(); return this.getMetadata();
}, },
set(value) { set(value) {
this.updateFields(value); this.updateMetadata(value);
} }
} }
}, },
@ -195,14 +195,14 @@ export default {
if (!this.editForms[editForm].saved) if (!this.editForms[editForm].saved)
hasUnsavedForms = true; hasUnsavedForms = true;
} }
if ((this.openedFieldId != '' && this.openedFieldId != undefined) || hasUnsavedForms ) { if ((this.openedMetadatumId != '' && this.openedMetadatumId != undefined) || hasUnsavedForms ) {
this.$modal.open({ this.$modal.open({
parent: this, parent: this,
component: CustomDialog, component: CustomDialog,
props: { props: {
icon: 'alert', icon: 'alert',
title: this.$i18n.get('label_warning'), 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: () => { onConfirm: () => {
this.onEditionCanceled(); this.onEditionCanceled();
next(); next();
@ -214,133 +214,133 @@ export default {
} }
}, },
methods: { methods: {
...mapActions('fields', [ ...mapActions('metadata', [
'fetchFieldTypes', 'fetchMetadatumTypes',
'updateFieldTypes', 'updateMetadatumTypes',
'fetchFields', 'fetchMetadata',
'sendField', 'sendMetadatum',
'deleteField', 'deleteMetadatum',
'updateFields', 'updateMetadata',
'updateCollectionFieldsOrder' 'updateCollectionMetadataOrder'
]), ]),
...mapGetters('fields',[ ...mapGetters('metadata',[
'getFieldTypes', 'getMetadatumTypes',
'getFields' 'getMetadata'
]), ]),
handleChange(event) { handleChange(event) {
if (event.added) { if (event.added) {
this.addNewField(event.added.element, event.added.newIndex); this.addNewMetadatum(event.added.element, event.added.newIndex);
} else if (event.removed) { } else if (event.removed) {
this.removeField(event.removed.element); this.removeMetadatum(event.removed.element);
} else if (event.moved) { } else if (event.moved) {
if (!this.isRepositoryLevel) if (!this.isRepositoryLevel)
this.updateFieldsOrder(); this.updateMetadataOrder();
} }
}, },
updateFieldsOrder() { updateMetadataOrder() {
let fieldsOrder = []; let metadataOrder = [];
for (let field of this.activeFieldList) { for (let metadatum of this.activeMetadatumList) {
fieldsOrder.push({'id': field.id, 'enabled': field.enabled}); 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) { onChangeEnable($event, index) {
this.activeFieldList[index].enabled = $event; this.activeMetadatumList[index].enabled = $event;
let fieldsOrder = []; let metadataOrder = [];
for (let field of this.activeFieldList) { for (let metadatum of this.activeMetadatumList) {
fieldsOrder.push({'id': field.id, 'enabled': field.enabled}); metadataOrder.push({'id': metadatum.id, 'enabled': metadatum.enabled});
} }
this.updateCollectionFieldsOrder({ collectionId: this.collectionId, fieldsOrder: fieldsOrder }); this.updateCollectionMetadataOrder({ collectionId: this.collectionId, metadataOrder: metadataOrder });
}, },
addFieldViaButton(fieldType) { addMetadatumViaButton(metadatumType) {
let lastIndex = this.activeFieldList.length; let lastIndex = this.activeMetadatumList.length;
this.addNewField(fieldType, lastIndex); this.addNewMetadatum(metadatumType, lastIndex);
// Higlights the clicker field // Higlights the clicker metadatum
this.hightlightedField = fieldType.name; this.hightlightedMetadatum = metadatumType.name;
}, },
addNewField(newField, newIndex) { addNewMetadatum(newMetadatum, newIndex) {
this.sendField({collectionId: this.collectionId, name: newField.name, fieldType: newField.className, status: 'auto-draft', isRepositoryLevel: this.isRepositoryLevel, newIndex: newIndex}) this.sendMetadatum({collectionId: this.collectionId, name: newMetadatum.name, metadatumType: newMetadatum.className, status: 'auto-draft', isRepositoryLevel: this.isRepositoryLevel, newIndex: newIndex})
.then((field) => { .then((metadatum) => {
if (!this.isRepositoryLevel) if (!this.isRepositoryLevel)
this.updateFieldsOrder(); this.updateMetadataOrder();
this.editField(field); this.editMetadatum(metadatum);
this.hightlightedField = ''; this.hightlightedMetadatum = '';
}) })
.catch((error) => { .catch((error) => {
this.$console.error(error); this.$console.error(error);
}); });
}, },
removeField(removedField) { removeMetadatum(removedMetadatum) {
this.deleteField({ collectionId: this.collectionId, fieldId: removedField.id, isRepositoryLevel: this.isRepositoryLevel}) this.deleteMetadatum({ collectionId: this.collectionId, metadatumId: removedMetadatum.id, isRepositoryLevel: this.isRepositoryLevel})
.then(() => { .then(() => {
if (!this.isRepositoryLevel) if (!this.isRepositoryLevel)
this.updateFieldsOrder(); this.updateMetadataOrder();
}) })
.catch(() => { .catch(() => {
}); });
}, },
editField(field) { editMetadatum(metadatum) {
// Closing collapse // Closing collapse
if (this.openedFieldId == field.id) { if (this.openedMetadatumId == metadatum.id) {
this.openedFieldId = ''; this.openedMetadatumId = '';
// Opening collapse // Opening collapse
} else { } else {
this.openedFieldId = field.id; this.openedMetadatumId = metadatum.id;
// First time opening // First time opening
if (this.editForms[this.openedFieldId] == undefined) { if (this.editForms[this.openedMetadatumId] == undefined) {
this.editForms[this.openedFieldId] = JSON.parse(JSON.stringify(field)); this.editForms[this.openedMetadatumId] = JSON.parse(JSON.stringify(metadatum));
this.editForms[this.openedFieldId].saved = true; this.editForms[this.openedMetadatumId].saved = true;
// Field inserted now // Metadatum inserted now
if (this.editForms[this.openedFieldId].status == 'auto-draft') { if (this.editForms[this.openedMetadatumId].status == 'auto-draft') {
this.editForms[this.openedFieldId].status = 'publish'; this.editForms[this.openedMetadatumId].status = 'publish';
this.editForms[this.openedFieldId].saved = false; this.editForms[this.openedMetadatumId].saved = false;
} }
} }
} }
}, },
onEditionFinished() { onEditionFinished() {
this.formWithErrors = ''; this.formWithErrors = '';
delete this.editForms[this.openedFieldId]; delete this.editForms[this.openedMetadatumId];
this.openedFieldId = ''; this.openedMetadatumId = '';
}, },
onEditionCanceled() { onEditionCanceled() {
this.formWithErrors = ''; this.formWithErrors = '';
delete this.editForms[this.openedFieldId]; delete this.editForms[this.openedMetadatumId];
this.openedFieldId = ''; this.openedMetadatumId = '';
} }
}, },
created() { created() {
this.isLoadingFieldTypes = true; this.isLoadingMetadatumTypes = true;
this.isLoadingFields = true; this.isLoadingMetadata = true;
this.fetchFieldTypes() this.fetchMetadatumTypes()
.then(() => { .then(() => {
this.isLoadingFieldTypes = false; this.isLoadingMetadatumTypes = false;
}) })
.catch(() => { .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) if (this.isRepositoryLevel)
this.collectionId = 'default'; this.collectionId = 'default';
else else
this.collectionId = this.$route.params.collectionId; 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(() => { .then(() => {
this.isLoadingFields = false; this.isLoadingMetadata = false;
}) })
.catch(() => { .catch(() => {
this.isLoadingFields = false; this.isLoadingMetadata = false;
}); });
}, },
mounted() { mounted() {
@ -378,7 +378,7 @@ export default {
width: 1em; width: 1em;
} }
.active-fields-area { .active-metadata-area {
font-size: 14px; font-size: 14px;
margin-right: 0.8em; margin-right: 0.8em;
margin-left: -0.8em; margin-left: -0.8em;
@ -394,7 +394,7 @@ export default {
padding-right: 1em; padding-right: 1em;
} }
&.fields-area-receive { &.metadata-area-receive {
border: 1px dashed gray; border: 1px dashed gray;
} }
@ -402,7 +402,7 @@ export default {
display: initial; display: initial;
} }
.active-field-item { .active-metadatum-item {
background-color: white; background-color: white;
padding: 0.7em 0.9em; padding: 0.7em 0.9em;
margin: 4px; margin: 4px;
@ -420,7 +420,7 @@ export default {
top: 2px; top: 2px;
position: relative; position: relative;
} }
.field-name { .metadatum-name {
text-overflow: ellipsis; text-overflow: ellipsis;
overflow-x: hidden; overflow-x: hidden;
white-space: nowrap; white-space: nowrap;
@ -467,18 +467,18 @@ export default {
&.not-focusable-item, &.not-focusable-item:hover { &.not-focusable-item, &.not-focusable-item:hover {
cursor: default; cursor: default;
.field-name { .metadatum-name {
color: $secondary; color: $secondary;
} }
.handle .label-details, .handle .icon { .handle .label-details, .handle .icon {
color: $gray !important; color: $gray !important;
} }
} }
&.disabled-field { &.disabled-metadatum {
color: $gray; color: $gray;
} }
} }
.active-field-item:hover:not(.not-sortable-item) { .active-metadatum-item:hover:not(.not-sortable-item) {
background-color: $secondary; background-color: $secondary;
border-color: $secondary; border-color: $secondary;
color: white !important; color: white !important;
@ -521,7 +521,7 @@ export default {
} }
} }
.available-fields-area { .available-metadata-area {
padding: 10px 0px 10px 10px; padding: 10px 0px 10px 10px;
margin: 0; margin: 0;
max-width: 280px; max-width: 280px;
@ -533,8 +533,8 @@ export default {
h3 { h3 {
margin: 1em 0em 1em 0em !important; margin: 1em 0em 1em 0em !important;
} }
.available-field-item::before, .available-metadatum-item::before,
.available-field-item::after { .available-metadatum-item::after {
display: none !important; display: none !important;
} }
} }
@ -545,7 +545,7 @@ export default {
font-weight: 500; font-weight: 500;
} }
.available-field-item { .available-metadatum-item {
padding: 0.7em; padding: 0.7em;
margin: 4px; margin: 4px;
background-color: white; background-color: white;
@ -568,7 +568,7 @@ export default {
position: relative; position: relative;
bottom: 1px; bottom: 1px;
} }
.field-name { .metadatum-name {
text-overflow: ellipsis; text-overflow: ellipsis;
overflow-x: hidden; overflow-x: hidden;
white-space: nowrap; white-space: nowrap;
@ -655,7 +655,7 @@ export default {
border-color: transparent white transparent transparent; border-color: transparent white transparent transparent;
} }
} }
.hightlighted-field { .hightlighted-metadatum {
background-color: white; background-color: white;
position: relative; position: relative;
left: 0px; left: 0px;
@ -676,7 +676,7 @@ export default {
animation-iteration-count: 2; animation-iteration-count: 2;
} }
} }
.available-field-item:hover { .available-metadatum-item:hover {
background-color: $secondary; background-color: $secondary;
border-color: $secondary; border-color: $secondary;
color: white; color: white;

View File

@ -34,12 +34,12 @@
<li> <li>
<router-link <router-link
tag="a" tag="a"
to="/fields" to="/metadata"
:class="activeRoute == 'FieldsPage' ? 'is-active':''"> :class="activeRoute == 'MetadataPage' ? 'is-active':''">
<b-icon <b-icon
size="is-small" size="is-small"
icon="format-list-bulleted-type"/> 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> </router-link>
</li> </li>
<li> <li>

View File

@ -54,14 +54,14 @@
<li class="level-item"> <li class="level-item">
<router-link <router-link
tag="a" tag="a"
:to="{ path: $routerHelper.getCollectionFieldsPath(id) }" :to="{ path: $routerHelper.getCollectionMetadataPath(id) }"
:class="activeRoute == 'FieldsList' ? 'is-active':''" :class="activeRoute == 'MetadataList' ? 'is-active':''"
:aria-label="$i18n.get('label_collection_fields')"> :aria-label="$i18n.get('label_collection_metadata')">
<b-icon <b-icon
size="is-small" size="is-small"
icon="format-list-bulleted-type"/> icon="format-list-bulleted-type"/>
<br> <br>
<span class="menu-text">{{ $i18n.getFrom('fields', 'name') }}</span> <span class="menu-text">{{ $i18n.getFrom('metadata', 'name') }}</span>
</router-link> </router-link>
</li> </li>
<li class="level-item"> <li class="level-item">

View File

@ -49,7 +49,7 @@
</div> </div>
<div <div
v-else-if="key === 'fields_order' || key === 'filters_order'" v-else-if="key === 'metadata_order' || key === 'filters_order'"
class="is-capitalized"> class="is-capitalized">
{{ `ID: ${o.id} Enabled: ${o.enabled ? o.enabled : 'false'}` }} {{ `ID: ${o.id} Enabled: ${o.enabled ? o.enabled : 'false'}` }}
</div> </div>
@ -132,7 +132,7 @@
</div> </div>
<div <div
v-else-if="key === 'fields_order' || key === 'filters_order'" v-else-if="key === 'metadata_order' || key === 'filters_order'"
class="is-capitalized" class="is-capitalized"
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }"> :class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }">
{{ `ID: ${d.id} Enabled: ${d.enabled ? d.enabled : 'false'}` }} {{ `ID: ${d.id} Enabled: ${d.enabled ? d.enabled : 'false'}` }}

View File

@ -51,7 +51,7 @@
</div> </div>
<div <div
v-else-if="key === 'fields_order' || key === 'filters_order'" v-else-if="key === 'metadata_order' || key === 'filters_order'"
class="is-capitalized"> class="is-capitalized">
{{ `ID: ${o.id} Enabled: ${o.enabled ? o.enabled : 'false'}` }} {{ `ID: ${o.id} Enabled: ${o.enabled ? o.enabled : 'false'}` }}
</div> </div>
@ -129,7 +129,7 @@
</div> </div>
<div <div
v-else-if="key === 'fields_order' || key === 'filters_order'" v-else-if="key === 'metadata_order' || key === 'filters_order'"
class="is-capitalized" class="is-capitalized"
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }"> :class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }">
{{ `ID: ${d.id} Enabled: ${d.enabled ? d.enabled : 'false'}` }} {{ `ID: ${d.id} Enabled: ${d.enabled ? d.enabled : 'false'}` }}

View File

@ -47,7 +47,7 @@
</div> </div>
<div <div
v-else-if="key === 'fields_order' || key === 'filters_order'" v-else-if="key === 'metadata_order' || key === 'filters_order'"
class="is-capitalized"> class="is-capitalized">
{{ `ID: ${d.id} Enabled: ${d.enabled}` }} {{ `ID: ${d.id} Enabled: ${d.enabled}` }}
</div> </div>

View File

@ -8,17 +8,17 @@ import Buefy from 'buefy';
import VTooltip from 'v-tooltip' import VTooltip from 'v-tooltip'
// Custom elements // Custom elements
import Text from '../../classes/field-types/text/Text.vue'; import Text from '../../classes/metadatum-types/text/Text.vue';
import Textarea from '../../classes/field-types/textarea/Textarea.vue'; import Textarea from '../../classes/metadatum-types/textarea/Textarea.vue';
import Selectbox from '../../classes/field-types/selectbox/Selectbox.vue'; import Selectbox from '../../classes/metadatum-types/selectbox/Selectbox.vue';
import Numeric from '../../classes/field-types/numeric/Numeric.vue'; import Numeric from '../../classes/metadatum-types/numeric/Numeric.vue';
import Date from '../../classes/field-types/date/Date.vue'; import Date from '../../classes/metadatum-types/date/Date.vue';
import Relationship from '../../classes/field-types/relationship/Relationship.vue'; import Relationship from '../../classes/metadatum-types/relationship/Relationship.vue';
import Category from '../../classes/field-types/category/Category.vue'; import Category from '../../classes/metadatum-types/category/Category.vue';
import FormRelationship from '../../classes/field-types/relationship/FormRelationship.vue'; import FormRelationship from '../../classes/metadatum-types/relationship/FormRelationship.vue';
import FormCategory from '../../classes/field-types/category/FormCategory.vue'; import FormCategory from '../../classes/metadatum-types/category/FormCategory.vue';
import FormSelectbox from '../../classes/field-types/selectbox/FormSelectbox.vue'; import FormSelectbox from '../../classes/metadatum-types/selectbox/FormSelectbox.vue';
import FilterCustomInterval from '../../classes/filter-types/custom-interval/CustomInterval.vue'; import FilterCustomInterval from '../../classes/filter-types/custom-interval/CustomInterval.vue';
import FilterSelectbox from '../../classes/filter-types/selectbox/Selectbox.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 FilterCategoryTaginput from '../../classes/filter-types/category/Taginput.vue';
import FilterCategorySelectbox from '../../classes/filter-types/category/Selectbox.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'; import TainacanFiltersList from '../../classes/filter-types/tainacan-filter-item.vue';
// Remaining imports // Remaining imports
@ -54,7 +54,7 @@ Vue.use(UserCapabilitiesPlugin);
Vue.use(ConsolePlugin, {visual: false}); Vue.use(ConsolePlugin, {visual: false});
Vue.use(VueMask); Vue.use(VueMask);
/* Fields */ /* Metadata */
Vue.component('tainacan-text', Text); Vue.component('tainacan-text', Text);
Vue.component('tainacan-textarea', Textarea); Vue.component('tainacan-textarea', Textarea);
Vue.component('tainacan-selectbox', Selectbox); Vue.component('tainacan-selectbox', Selectbox);

View File

@ -7,7 +7,7 @@ import CollectionsPage from '../pages/lists/collections-page.vue'
import CollectionPage from '../pages/singles/collection-page.vue' import CollectionPage from '../pages/singles/collection-page.vue'
import ItemsPage from '../pages/lists/items-page.vue' import ItemsPage from '../pages/lists/items-page.vue'
import ItemPage from '../pages/singles/item-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 FiltersPage from '../pages/lists/filters-page.vue'
import CategoriesPage from '../pages/lists/categories-page.vue' import CategoriesPage from '../pages/lists/categories-page.vue'
import CategoryPage from '../pages/singles/category-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 // Listing components
import FiltersList from '../components/lists/filters-list.vue' 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); 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/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: '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: '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: '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'} } { 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: '/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', 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'} }, { path: '/taxonomies/new', name: 'CategoryCreationForm', component: CategoryEditionForm, meta: {title: i18nGet('title_create_category_page'), icon: 'shape'} },

View File

@ -4,17 +4,17 @@ import Buefy from 'buefy';
import VTooltip from 'v-tooltip' import VTooltip from 'v-tooltip'
// Custom elements // Custom elements
import Text from '../../classes/field-types/text/Text.vue'; import Text from '../../classes/metadatum-types/text/Text.vue';
import Textarea from '../../classes/field-types/textarea/Textarea.vue'; import Textarea from '../../classes/metadatum-types/textarea/Textarea.vue';
import Selectbox from '../../classes/field-types/selectbox/Selectbox.vue'; import Selectbox from '../../classes/metadatum-types/selectbox/Selectbox.vue';
import Numeric from '../../classes/field-types/numeric/Numeric.vue'; import Numeric from '../../classes/metadatum-types/numeric/Numeric.vue';
import Date from '../../classes/field-types/date/Date.vue'; import Date from '../../classes/metadatum-types/date/Date.vue';
import Relationship from '../../classes/field-types/relationship/Relationship.vue'; import Relationship from '../../classes/metadatum-types/relationship/Relationship.vue';
import Category from '../../classes/field-types/category/Category.vue'; import Category from '../../classes/metadatum-types/category/Category.vue';
import FormRelationship from '../../classes/field-types/relationship/FormRelationship.vue'; import FormRelationship from '../../classes/metadatum-types/relationship/FormRelationship.vue';
import FormCategory from '../../classes/field-types/category/FormCategory.vue'; import FormCategory from '../../classes/metadatum-types/category/FormCategory.vue';
import FormSelectbox from '../../classes/field-types/selectbox/FormSelectbox.vue'; import FormSelectbox from '../../classes/metadatum-types/selectbox/FormSelectbox.vue';
import FilterCustomInterval from '../../classes/filter-types/custom-interval/CustomInterval.vue'; import FilterCustomInterval from '../../classes/filter-types/custom-interval/CustomInterval.vue';
import FilterSelectbox from '../../classes/filter-types/selectbox/Selectbox.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 FilterCategoryTaginput from '../../classes/filter-types/category/Taginput.vue';
import FilterCategorySelectbox from '../../classes/filter-types/category/Selectbox.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 TaincanFiltersList from '../../classes/filter-types/tainacan-filter-item.vue';
import ItemsPage from '../pages/lists/items-page.vue'; import ItemsPage from '../pages/lists/items-page.vue';
import TableViewMode from '../../theme-helper/table-view-mode.vue'; import TableViewMode from '../../theme-helper/table-view-mode.vue';
@ -47,7 +47,7 @@ Vue.use(UserPrefsPlugin);
Vue.use(RouterHelperPlugin); Vue.use(RouterHelperPlugin);
Vue.use(ConsolePlugin, {visual: false}); Vue.use(ConsolePlugin, {visual: false});
/* Fields */ /* Metadata */
Vue.component('tainacan-text', Text); Vue.component('tainacan-text', Text);
Vue.component('tainacan-textarea', Textarea); Vue.component('tainacan-textarea', Textarea);
Vue.component('tainacan-selectbox', Selectbox); Vue.component('tainacan-selectbox', Selectbox);

View File

@ -162,8 +162,8 @@ RouterHelperPlugin.install = function (Vue, options = {}) {
getCollectionItemsPath(collectionId, query) { getCollectionItemsPath(collectionId, query) {
return '/collections/'+ collectionId + '/items/?' + qs.stringify(query); return '/collections/'+ collectionId + '/items/?' + qs.stringify(query);
}, },
getCollectionFieldsPath(collectionId) { getCollectionMetadataPath(collectionId) {
return '/collections/'+ collectionId + '/fields/'; return '/collections/'+ collectionId + '/metadata/';
}, },
getCollectionFiltersPath(collectionId) { getCollectionFiltersPath(collectionId) {
return '/collections/'+ collectionId + '/filters/'; return '/collections/'+ collectionId + '/filters/';
@ -183,8 +183,8 @@ RouterHelperPlugin.install = function (Vue, options = {}) {
getFiltersPath(query) { getFiltersPath(query) {
return '/filters/?' + qs.stringify(query); return '/filters/?' + qs.stringify(query);
}, },
getFieldsPath(query) { getMetadataPath(query) {
return '/fields/?' + qs.stringify(query); return '/metadata/?' + qs.stringify(query);
}, },
getEventsPath(query) { getEventsPath(query) {
return '/events/?' + qs.stringify(query); return '/events/?' + qs.stringify(query);
@ -218,11 +218,11 @@ RouterHelperPlugin.install = function (Vue, options = {}) {
getNewItemPath(collectionId) { getNewItemPath(collectionId) {
return '/collections/' + collectionId + '/items/new'; return '/collections/' + collectionId + '/items/new';
}, },
getNewCollectionFieldPath(collectionId) { getNewCollectionMetadatumPath(collectionId) {
return '/collections/' + collectionId + '/fields/'; return '/collections/' + collectionId + '/metadata/';
}, },
getNewFieldPath() { getNewMetadatumPath() {
return '/fields'; return '/metadata';
}, },
getNewCollectionFilterPath(collectionId) { getNewCollectionFilterPath(collectionId) {
return '/collections/' + collectionId + '/filters/'; return '/collections/' + collectionId + '/filters/';

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="primary-page page-container"> <div class="primary-page page-container">
<b-loading :active.sync="isLoadingFieldMappers"/> <b-loading :active.sync="isLoadingMetadatumMappers"/>
<tainacan-title /> <tainacan-title />
<div <div
class="sub-header" class="sub-header"
@ -24,14 +24,14 @@
</router-link> </router-link>
</b-dropdown-item> </b-dropdown-item>
<b-dropdown-item <b-dropdown-item
:key="field_mapper.slug" :key="metadatum_mapper.slug"
v-for="field_mapper in field_mappers" v-for="metadatum_mapper in metadatum_mappers"
v-if="field_mapper.metadata != false"> v-if="metadatum_mapper.metadata != false">
<router-link <router-link
:id="'a-create-collection-' + field_mapper.slug" :id="'a-create-collection-' + metadatum_mapper.slug"
tag="div" tag="div"
:to="{ path: $routerHelper.getNewMappedCollectionPath(field_mapper.slug) }"> :to="{ path: $routerHelper.getNewMappedCollectionPath(metadatum_mapper.slug) }">
{{ $i18n.get(field_mapper.name) }} {{ $i18n.get(metadatum_mapper.name) }}
</router-link> </router-link>
</b-dropdown-item> </b-dropdown-item>
</b-dropdown> </b-dropdown>
@ -140,7 +140,7 @@ export default {
totalCollections: 0, totalCollections: 0,
page: 1, page: 1,
collectionsPerPage: 12, collectionsPerPage: 12,
isLoadingFieldMappers: true, isLoadingMetadatumMappers: true,
status: '' status: ''
} }
}, },
@ -151,14 +151,14 @@ export default {
...mapActions('collection', [ ...mapActions('collection', [
'fetchCollections', 'fetchCollections',
]), ]),
...mapActions('fields', [ ...mapActions('metadata', [
'fetchFieldMappers' 'fetchMetadatumMappers'
]), ]),
...mapGetters('collection', [ ...mapGetters('collection', [
'getCollections' 'getCollections'
]), ]),
...mapGetters('fields', [ ...mapGetters('metadata', [
'getFieldMappers' 'getMetadatumMappers'
]), ]),
onChangeTab(status) { onChangeTab(status) {
this.status = status; this.status = status;
@ -192,9 +192,9 @@ export default {
} }
}, },
computed: { computed: {
field_mappers: { metadatum_mappers: {
get() { get() {
return this.getFieldMappers(); return this.getMetadatumMappers();
} }
}, },
collections() { collections() {
@ -202,7 +202,7 @@ export default {
} }
}, },
created() { created() {
this.isLoadingFieldTypes = true; this.isLoadingMetadatumTypes = true;
this.$userPrefs.get('collections_per_page') this.$userPrefs.get('collections_per_page')
.then((value) => { .then((value) => {
this.collectionsPerPage = value; this.collectionsPerPage = value;
@ -210,12 +210,12 @@ export default {
.catch(() => { .catch(() => {
this.$userPrefs.set('collections_per_page', 12, null); this.$userPrefs.set('collections_per_page', 12, null);
}); });
this.fetchFieldMappers() this.fetchMetadatumMappers()
.then(() => { .then(() => {
this.isLoadingFieldMappers = false; this.isLoadingMetadatumMappers = false;
}) })
.catch(() => { .catch(() => {
this.isLoadingFieldMappers = false; this.isLoadingMetadatumMappers = false;
}); });
}, },
mounted(){ mounted(){

View File

@ -104,7 +104,7 @@
class="search-control"> class="search-control">
<b-loading <b-loading
:is-full-page="false" :is-full-page="false"
:active.sync="isLoadingFields"/> :active.sync="isLoadingMetadata"/>
<!-- Item Creation Dropdown, only on Admin --> <!-- Item Creation Dropdown, only on Admin -->
<div <div
class="search-control-item" class="search-control-item"
@ -136,12 +136,12 @@
</b-dropdown> </b-dropdown>
</div> </div>
<!-- Displayed Fields Dropdown --> <!-- Displayed Metadata Dropdown -->
<div <div
v-if="!isOnTheme || registeredViewModes[viewMode].dynamic_metadata" v-if="!isOnTheme || registeredViewModes[viewMode].dynamic_metadata"
class="search-control-item"> class="search-control-item">
<b-dropdown <b-dropdown
ref="displayedFieldsDropdown" ref="displayedMetadataDropdown"
:mobile-modal="false" :mobile-modal="false"
:disabled="totalItems <= 0 || adminViewMode == 'grid'" :disabled="totalItems <= 0 || adminViewMode == 'grid'"
class="show"> class="show">
@ -153,7 +153,7 @@
</button> </button>
<div class="metadata-options-container"> <div class="metadata-options-container">
<b-dropdown-item <b-dropdown-item
v-for="(column, index) in localTableFields" v-for="(column, index) in localTableMetadata"
:key="index" :key="index"
class="control" class="control"
custom> custom>
@ -166,7 +166,7 @@
</div> </div>
<div class="dropdown-item-apply"> <div class="dropdown-item-apply">
<button <button
@click="onChangeDisplayedFields()" @click="onChangeDisplayedMetadata()"
class="button is-success"> class="button is-success">
{{ $i18n.get('label_apply_changes') }} {{ $i18n.get('label_apply_changes') }}
</button> </button>
@ -182,19 +182,20 @@
@input="onChangeOrderBy($event)" @input="onChangeOrderBy($event)"
:placeholder="$i18n.get('label_sorting')"> :placeholder="$i18n.get('label_sorting')">
<option <option
v-for="field in tableFields" v-for="metadatum in tableMetadata"
v-if=" v-if="
field.id === 'creation_date' || metadatum.id === 'creation_date' ||
field.id === 'author_name' || ( metadatum.id === 'author_name' || (
field.id !== undefined && metadatum.id !== undefined &&
field.field_type_object.related_mapped_prop !== 'description' && metadatum.metadatum_type_object &&
field.field_type_object.primitive_type !== 'term' && metadatum.metadatum_type_object.related_mapped_prop !== 'description' &&
field.field_type_object.primitive_type !== 'item' && metadatum.metadatum_type_object.primitive_type !== 'term' &&
field.field_type_object.primitive_type !== 'compound' metadatum.metadatum_type_object.primitive_type !== 'item' &&
metadatum.metadatum_type_object.primitive_type !== 'compound'
)" )"
:value="field" :value="metadatum"
:key="field.id"> :key="metadatum.id">
{{ field.name }} {{ metadatum.name }}
</option> </option>
</b-select> </b-select>
<button <button
@ -291,7 +292,7 @@
</div> </div>
<advanced-search <advanced-search
:is-repository-level="isRepositoryLevel" :is-repository-level="isRepositoryLevel"
:metadata-list="fields" /> :metadata-list="metadata" />
</div> </div>
@ -336,7 +337,7 @@
advancedSearchResults" advancedSearchResults"
:collection-id="collectionId" :collection-id="collectionId"
:table-fields="tableFields" :table-metadata="tableMetadata"
:items="items" :items="items"
:is-loading="isLoadingItems" :is-loading="isLoadingItems"
:is-on-trash="status == 'trash'" :is-on-trash="status == 'trash'"
@ -350,7 +351,7 @@
!openAdvancedSearch" !openAdvancedSearch"
:collection-id="collectionId" :collection-id="collectionId"
:table-fields="tableFields" :table-metadata="tableMetadata"
:items="items" :items="items"
:is-loading="isLoadingItems" :is-loading="isLoadingItems"
:is-on-trash="status == 'trash'" :is-on-trash="status == 'trash'"
@ -369,7 +370,7 @@
registeredViewModes[viewMode] != undefined && registeredViewModes[viewMode] != undefined &&
registeredViewModes[viewMode].type == 'component'" registeredViewModes[viewMode].type == 'component'"
:collection-id="collectionId" :collection-id="collectionId"
:table-fields="tableFields" :table-metadata="tableMetadata"
:items="items" :items="items"
:is-loading="isLoadingItems" :is-loading="isLoadingItems"
:is="'table-view-mode'"/> :is="'table-view-mode'"/>
@ -430,18 +431,18 @@
data() { data() {
return { return {
isRepositoryLevel: false, isRepositoryLevel: false,
tableFields: [], tableMetadata: [],
prefTableFields: [], prefTableMetadata: [],
isLoadingItems: false, isLoadingItems: false,
isLoadingFilters: false, isLoadingFilters: false,
isLoadingFields: false, isLoadingMetadata: false,
hasFiltered: false, hasFiltered: false,
isFiltersMenuCompressed: false, isFiltersMenuCompressed: false,
collapseAll: true, collapseAll: true,
isOnTheme: false, isOnTheme: false,
futureSearchQuery: '', futureSearchQuery: '',
isHeaderShrinked: false, isHeaderShrinked: false,
localTableFields: [], localTableMetadata: [],
registeredViewModes: tainacan_plugin.registered_view_modes, registeredViewModes: tainacan_plugin.registered_view_modes,
adminViewMode: 'table', adminViewMode: 'table',
openAdvancedSearch: false, openAdvancedSearch: false,
@ -466,8 +467,8 @@
filters() { filters() {
return this.getFilters(); return this.getFilters();
}, },
fields() { metadata() {
return this.getFields(); return this.getMetadata();
}, },
searchQuery() { searchQuery() {
return this.getSearchQuery(); return this.getSearchQuery();
@ -492,8 +493,8 @@
AdvancedSearch, AdvancedSearch,
}, },
watch: { watch: {
tableFields() { tableMetadata() {
this.localTableFields = JSON.parse(JSON.stringify(this.tableFields)); this.localTableMetadata = JSON.parse(JSON.stringify(this.tableMetadata));
} }
}, },
methods: { methods: {
@ -501,11 +502,11 @@
'getItems', 'getItems',
'getItemsListTemplate' 'getItemsListTemplate'
]), ]),
...mapActions('fields', [ ...mapActions('metadata', [
'fetchFields' 'fetchMetadata'
]), ]),
...mapGetters('fields', [ ...mapGetters('metadata', [
'getFields' 'getMetadata'
]), ]),
...mapActions('filter', [ ...mapActions('filter', [
'fetchFilters' 'fetchFilters'
@ -524,8 +525,8 @@
updateSearch() { updateSearch() {
this.$eventBusSearch.setSearchQuery(this.futureSearchQuery); this.$eventBusSearch.setSearchQuery(this.futureSearchQuery);
}, },
onChangeOrderBy(field) { onChangeOrderBy(metadatum) {
this.$eventBusSearch.setOrderBy(field); this.$eventBusSearch.setOrderBy(metadatum);
}, },
onChangeOrder() { onChangeOrder() {
this.order == 'DESC' ? this.$eventBusSearch.setOrder('ASC') : this.$eventBusSearch.setOrder('DESC'); this.order == 'DESC' ? this.$eventBusSearch.setOrder('ASC') : this.$eventBusSearch.setOrder('DESC');
@ -536,31 +537,31 @@
onChangeViewMode(viewMode) { onChangeViewMode(viewMode) {
this.$eventBusSearch.setViewMode(viewMode); this.$eventBusSearch.setViewMode(viewMode);
}, },
onChangeDisplayedFields() { onChangeDisplayedMetadata() {
let fetchOnlyFieldIds = []; 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; this.tableMetadata[i].display = this.localTableMetadata[i].display;
if (this.tableFields[i].id != undefined) { if (this.tableMetadata[i].id != undefined) {
if (this.tableFields[i].display) { if (this.tableMetadata[i].display) {
fetchOnlyFieldIds.push(this.tableFields[i].id); fetchOnlyMetadatumIds.push(this.tableMetadata[i].id);
} }
} }
} }
let thumbnailField = this.localTableFields.find(field => field.slug == 'thumbnail'); let thumbnailMetadatum = this.localTableMetadata.find(metadatum => metadatum.slug == 'thumbnail');
let creationDateField = this.localTableFields.find(field => field.slug == 'creation_date'); let creationDateMetadatum = this.localTableMetadata.find(metadatum => metadatum.slug == 'creation_date');
let authorNameField = this.localTableFields.find(field => field.slug == 'author_name'); let authorNameMetadatum = this.localTableMetadata.find(metadatum => metadatum.slug == 'author_name');
this.$eventBusSearch.addFetchOnly({ this.$eventBusSearch.addFetchOnly({
'0': thumbnailField.display ? 'thumbnail' : null, '0': thumbnailMetadatum.display ? 'thumbnail' : null,
'meta': fetchOnlyFieldIds, 'meta': fetchOnlyMetadatumIds,
'1': creationDateField.display ? 'creation_date' : null, '1': creationDateMetadatum.display ? 'creation_date' : null,
'2': authorNameField.display ? 'author_name': null '2': authorNameMetadatum.display ? 'author_name': null
}); });
this.$refs.displayedFieldsDropdown.toggle(); this.$refs.displayedMetadataDropdown.toggle();
}, },
prepareFieldsAndFilters() { prepareMetadataAndFilters() {
this.isLoadingFilters = true; this.isLoadingFilters = true;
@ -573,89 +574,89 @@
.then(() => this.isLoadingFilters = false) .then(() => this.isLoadingFilters = false)
.catch(() => this.isLoadingFilters = false); .catch(() => this.isLoadingFilters = false);
this.isLoadingFields = true; this.isLoadingMetadata = true;
// Processing is done inside a local variable // Processing is done inside a local variable
let fields = []; let metadata = [];
this.fetchFields({ this.fetchMetadata({
collectionId: this.collectionId, collectionId: this.collectionId,
isRepositoryLevel: this.isRepositoryLevel, isRepositoryLevel: this.isRepositoryLevel,
isContextEdit: !this.isOnTheme isContextEdit: !this.isOnTheme
}) })
.then(() => { .then(() => {
fields.push({ metadata.push({
name: this.$i18n.get('label_thumbnail'), name: this.$i18n.get('label_thumbnail'),
field: 'row_thumbnail', metadatum: 'row_thumbnail',
field_type: undefined, metadatum_type: undefined,
slug: 'thumbnail', slug: 'thumbnail',
id: undefined, id: undefined,
display: true display: true
}); });
let fetchOnlyFieldIds = []; let fetchOnlyMetadatumIds = [];
for (let field of this.fields) { for (let metadatum of this.metadata) {
if (field.display !== 'never') { if (metadatum.display !== 'never') {
let display; let display;
if (field.display == 'no') if (metadatum.display == 'no')
display = false; display = false;
else if (field.display == 'yes') else if (metadatum.display == 'yes')
display = true; display = true;
fields.push( metadata.push(
{ {
name: field.name, name: metadatum.name,
field: field.description, metadatum: metadatum.description,
slug: field.slug, slug: metadatum.slug,
field_type: field.field_type, metadatum_type: metadatum.metadatum_type,
field_type_object: field.field_type_object, metadatum_type_object: metadatum.metadatum_type_object,
id: field.id, id: metadatum.id,
display: display display: display
} }
); );
if (display) if (display)
fetchOnlyFieldIds.push(field.id); fetchOnlyMetadatumIds.push(metadatum.id);
} }
} }
fields.push({ metadata.push({
name: this.$i18n.get('label_creation_date'), name: this.$i18n.get('label_creation_date'),
field: 'row_creation', metadatum: 'row_creation',
field_type: undefined, metadatum_type: undefined,
slug: 'creation_date', slug: 'creation_date',
id: undefined, id: undefined,
display: true display: true
}); });
fields.push({ metadata.push({
name: this.$i18n.get('label_created_by'), name: this.$i18n.get('label_created_by'),
field: 'row_author', metadatum: 'row_author',
field_type: undefined, metadatum_type: undefined,
slug: 'author_name', slug: 'author_name',
id: undefined, id: undefined,
display: true display: true
}); });
// this.prefTableFields = this.tableFields; // this.prefTableMetadata = this.tableMetadata;
// this.$userPrefs.get('table_columns_' + this.collectionId) // this.$userPrefs.get('table_columns_' + this.collectionId)
// .then((value) => { // .then((value) => {
// this.prefTableFields = value; // this.prefTableMetadata = value;
// }) // })
// .catch((error) => { // .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({ this.$eventBusSearch.addFetchOnly({
'0': 'thumbnail', '0': 'thumbnail',
'meta': fetchOnlyFieldIds, 'meta': fetchOnlyMetadatumIds,
'1': 'creation_date', '1': 'creation_date',
'2': 'author_name' '2': 'author_name'
}); });
this.isLoadingFields = false; this.isLoadingMetadata = false;
this.tableFields = fields; this.tableMetadata = metadata;
}) })
.catch(() => { .catch(() => {
this.isLoadingFields = false; this.isLoadingMetadata = false;
}); });
} }
}, },
@ -675,12 +676,12 @@
this.hasFiltered = hasFiltered; this.hasFiltered = hasFiltered;
}); });
this.$eventBusSearch.$on('hasToPrepareFieldsAndFilters', (to) => { this.$eventBusSearch.$on('hasToPrepareMetadataAndFilters', (to) => {
/* This condition is to prevent a incorrect fetch by filter or fields when we come from items /* 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 * at collection level to items page at repository level
*/ */
if (this.collectionId === to.params.collectionId) { if (this.collectionId === to.params.collectionId) {
this.prepareFieldsAndFilters(); this.prepareMetadataAndFilters();
} }
}); });
@ -692,8 +693,8 @@
}, },
mounted() { mounted() {
this.prepareFieldsAndFilters(); this.prepareMetadataAndFilters();
this.localTableFields = JSON.parse(JSON.stringify(this.tableFields)); this.localTableMetadata = JSON.parse(JSON.stringify(this.tableMetadata));
// Watch Scroll for shrinking header, only on Admin at collection level // Watch Scroll for shrinking header, only on Admin at collection level
if (!this.isRepositoryLevel && !this.isOnTheme) { if (!this.isRepositoryLevel && !this.isOnTheme) {

View File

@ -1,21 +1,21 @@
<template> <template>
<div class="primary-page page-container"> <div class="primary-page page-container">
<tainacan-title /> <tainacan-title />
<fields-list/> <metadata-list/>
</div> </div>
</template> </template>
<script> <script>
import FieldsList from '../../components/lists/fields-list.vue'; import MetadataList from '../../components/lists/metadata-list.vue';
export default { export default {
name: 'FieldsPage', name: 'MetadataPage',
data(){ data(){
return { return {
} }
}, },
components: { components: {
FieldsList MetadataList
} }
} }
</script> </script>

View File

@ -89,7 +89,7 @@
<div <div
v-show="!isMetadataColumnCompressed" v-show="!isMetadataColumnCompressed"
class="column is-4-5"> class="column is-4-5">
<label class="section-label">{{ $i18n.get('fields') }}</label> <label class="section-label">{{ $i18n.get('metadata') }}</label>
<br> <br>
<a <a
class="collapse-all" class="collapse-all"
@ -100,10 +100,10 @@
:icon=" open ? 'menu-down' : 'menu-right'"/> :icon=" open ? 'menu-down' : 'menu-right'"/>
</a> </a>
<!-- Fields -------------------------------- --> <!-- Metadata -------------------------------- -->
<div> <div>
<div <div
v-for="(field, index) of fieldList" v-for="(metadatum, index) of metadatumList"
:key="index" :key="index"
class="field"> class="field">
<b-collapse :open="open"> <b-collapse :open="open">
@ -115,17 +115,17 @@
type="is-secondary" type="is-secondary"
:icon="props.open ? 'menu-down' : 'menu-right'" :icon="props.open ? 'menu-down' : 'menu-right'"
/> />
{{ field.field.name }} {{ metadatum.metadatum.name }}
</label> </label>
<div <div
v-if="field.date_i18n" v-if="metadatum.date_i18n"
class="content"> class="content">
<p v-html="field.date_i18n"/> <p v-html="metadatum.date_i18n"/>
</div> </div>
<div <div
v-else v-else
class="content"> class="content">
<p v-html="field.value_as_html"/> <p v-html="metadatum.value_as_html"/>
</div> </div>
</b-collapse> </b-collapse>
</div> </div>
@ -157,16 +157,16 @@
...mapActions('item', [ ...mapActions('item', [
'fetchItem', 'fetchItem',
'fetchAttachments', 'fetchAttachments',
'fetchFields', 'fetchMetadata',
]), ]),
...mapGetters('item', [ ...mapGetters('item', [
'getItem', 'getItem',
'getFields', 'getMetadata',
'getAttachments' 'getAttachments'
]), ]),
loadMetadata() { loadMetadata() {
// Obtains Item Field // Obtains Item Metadatum
this.fetchFields(this.itemId).then(() => { this.fetchMetadata(this.itemId).then(() => {
this.isLoading = false; this.isLoading = false;
}); });
}, },
@ -175,8 +175,8 @@
item() { item() {
return this.getItem(); return this.getItem();
}, },
fieldList() { metadatumList() {
return JSON.parse(JSON.stringify(this.getFields())); return JSON.parse(JSON.stringify(this.getMetadata()));
}, },
attachmentsList() { attachmentsList() {
return this.getAttachments(); return this.getAttachments();

View File

@ -20,7 +20,7 @@
display: inline-block; display: inline-block;
white-space: nowrap; white-space: nowrap;
} }
.required-field-asterisk { .required-metadatum-asterisk {
color: $gray; color: $gray;
&.is-danger { &.is-danger {
color: $danger; color: $danger;

View File

@ -12,13 +12,13 @@ return apply_filters('tainacan-admin-i18n',[
'repository' => __( 'Repository', 'tainacan' ), 'repository' => __( 'Repository', 'tainacan' ),
'collections' => __( 'Collections', 'tainacan' ), 'collections' => __( 'Collections', 'tainacan' ),
'items' => __( 'Items', 'tainacan' ), 'items' => __( 'Items', 'tainacan' ),
'fields' => __( 'Metadata', 'tainacan' ), 'metadata' => __( 'Metadata', 'tainacan' ),
'filters' => __( 'Filters', 'tainacan' ), 'filters' => __( 'Filters', 'tainacan' ),
'taxonomies' => __( 'Taxonomies', 'tainacan' ), 'taxonomies' => __( 'Taxonomies', 'tainacan' ),
'events' => __( 'Events', 'tainacan' ), 'events' => __( 'Events', 'tainacan' ),
'collection' => __( 'Collection', 'tainacan' ), 'collection' => __( 'Collection', 'tainacan' ),
'item' => __( 'Item', 'tainacan' ), 'item' => __( 'Item', 'tainacan' ),
'field' => __( 'Metadata', 'tainacan' ), 'metadatum' => __( 'Metadata', 'tainacan' ),
'filter' => __( 'Filter', 'tainacan' ), 'filter' => __( 'Filter', 'tainacan' ),
'taxonomy' => __( 'Taxonomia', 'tainacan' ), 'taxonomy' => __( 'Taxonomia', 'tainacan' ),
'event' => __( 'Event', 'tainacan' ), 'event' => __( 'Event', 'tainacan' ),
@ -51,7 +51,7 @@ return apply_filters('tainacan-admin-i18n',[
'new_blank_collection' => __( 'New Blank Collection', 'tainacan' ), 'new_blank_collection' => __( 'New Blank Collection', 'tainacan' ),
'split' => __( 'Split', 'tainacan' ), 'split' => __( 'Split', 'tainacan' ),
'unified' => __( 'Unified', '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' ), 'clear_search' => __( 'Clear search', 'tainacan' ),
// Wordpress Status // Wordpress Status
@ -66,14 +66,14 @@ return apply_filters('tainacan-admin-i18n',[
// Page Titles (used mainly on Router) // Page Titles (used mainly on Router)
'title_repository_collections_page' => __( 'Repository Collections', 'tainacan' ), 'title_repository_collections_page' => __( 'Repository Collections', 'tainacan' ),
'title_items_page' => __( 'Items', '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_repository_filters_page' => __( 'Repository Filters', 'tainacan' ),
'title_categories_page' => __( 'Categories Page', 'tainacan' ), 'title_categories_page' => __( 'Categories Page', 'tainacan' ),
'title_terms_page' => __( 'Terms', 'tainacan' ), 'title_terms_page' => __( 'Terms', 'tainacan' ),
'title_repository_events_page' => __( 'Repository Events', 'tainacan' ), 'title_repository_events_page' => __( 'Repository Events', 'tainacan' ),
'title_collection_page' => __( 'Collection', 'tainacan' ), 'title_collection_page' => __( 'Collection', 'tainacan' ),
'title_item_page' => __( 'Item', 'tainacan' ), 'title_item_page' => __( 'Item', 'tainacan' ),
'title_field_page' => __( 'Metadata', 'tainacan' ), 'title_metadatum_page' => __( 'Metadata', 'tainacan' ),
'title_collection_events' => __( 'Collection Events', 'tainacan' ), 'title_collection_events' => __( 'Collection Events', 'tainacan' ),
'title_filter_page' => __( 'Filter', 'tainacan' ), 'title_filter_page' => __( 'Filter', 'tainacan' ),
'title_category_page' => __( 'Taxonomy', 'tainacan' ), 'title_category_page' => __( 'Taxonomy', 'tainacan' ),
@ -87,8 +87,8 @@ return apply_filters('tainacan-admin-i18n',[
'title_edit_item' => __( 'Edit Item', 'tainacan' ), 'title_edit_item' => __( 'Edit Item', 'tainacan' ),
'title_category_edition_page' => __( 'Taxonomy Edition', 'tainacan' ), 'title_category_edition_page' => __( 'Taxonomy Edition', 'tainacan' ),
'title_filter_edition' => __( 'Filter Edition', 'tainacan' ), 'title_filter_edition' => __( 'Filter Edition', 'tainacan' ),
'title_field_edition' => __( 'Metadata Edition', 'tainacan' ), 'title_metadatum_edition' => __( 'Metadata Edition', 'tainacan' ),
'title_collection_fields_edition' => __( 'Edit Metadata of', 'tainacan' ), 'title_collection_metadata_edition' => __( 'Edit Metadata of', 'tainacan' ),
'title_collection_filters_edition' => __( 'Edit Filters of', 'tainacan' ), 'title_collection_filters_edition' => __( 'Edit Filters of', 'tainacan' ),
// Labels (used mainly on Aria Labels and Inputs) // 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_categories_per_page' => __( 'Categories per Page:', 'tainacan' ),
'label_events_per_page' => __( 'Events per Page:', 'tainacan' ), 'label_events_per_page' => __( 'Events per Page:', 'tainacan' ),
'label_items_per_page' => __( 'Items per Page:', 'tainacan' ), 'label_items_per_page' => __( 'Items per Page:', 'tainacan' ),
'label_active_fields' => __( 'Active Metadata', 'tainacan' ), 'label_active_metadata' => __( 'Active Metadata', 'tainacan' ),
'label_available_fields' => __( 'Available Metadata', 'tainacan' ), 'label_available_metadata' => __( 'Available Metadata', 'tainacan' ),
'label_available_field_types' => __( 'Available Metadata Types', 'tainacan' ), 'label_available_metadatum_types' => __( 'Available Metadata Types', 'tainacan' ),
'label_active_filters' => __( 'Active Filters', 'tainacan' ), 'label_active_filters' => __( 'Active Filters', 'tainacan' ),
'label_filter_type' => __( 'Filter Type', 'tainacan' ), 'label_filter_type' => __( 'Filter Type', 'tainacan' ),
'label_available_filters' => __( 'Available Filters', 'tainacan' ), 'label_available_filters' => __( 'Available Filters', 'tainacan' ),
@ -141,7 +141,7 @@ return apply_filters('tainacan-admin-i18n',[
'label_no' => __( 'No', 'tainacan' ), 'label_no' => __( 'No', 'tainacan' ),
'label_approved' => __( 'Approved', 'tainacan' ), 'label_approved' => __( 'Approved', 'tainacan' ),
'label_collection_related' => __( 'Collection Related', '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_allow_repeated_items' => __( 'Allow repeated items', 'tainacan' ),
'label_select_category' => __( 'Select taxonomy', 'tainacan' ), 'label_select_category' => __( 'Select taxonomy', 'tainacan' ),
'label_select_category_input_type' => __( 'Input type', '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' => __( 'Creation', 'tainacan' ),
'label_creation_date' => __( 'Creation date', 'tainacan' ), 'label_creation_date' => __( 'Creation date', 'tainacan' ),
'label_collection_items' => __( 'Collection Items', '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_collection_filters' => __( 'Collection Filters', 'tainacan' ),
'label_parent_term' => __( 'Parent Term', 'tainacan' ), 'label_parent_term' => __( 'Parent Term', 'tainacan' ),
'label_new_term' => __( 'New 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_empty_header_image' => __( 'Empty Header Image', 'tainacan' ),
'label_enable_cover_page' => __( 'Enable Cover Page', 'tainacan' ), 'label_enable_cover_page' => __( 'Enable Cover Page', 'tainacan' ),
'label_cover_page' => __( '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' => __( 'Display on Listing', 'tainacan' ),
'label_display_default' => __( 'Display by default', 'tainacan' ), 'label_display_default' => __( 'Display by default', 'tainacan' ),
'label_display_never' => __( 'Never displayed', '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_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_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_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_items' => __( 'Showing items ', 'tainacan' ),
'info_showing_collections' => __( 'Showing collections ', 'tainacan' ), 'info_showing_collections' => __( 'Showing collections ', 'tainacan' ),
'info_showing_categories' => __( 'Showing categories ', 'tainacan' ), 'info_showing_categories' => __( 'Showing categories ', 'tainacan' ),
@ -282,7 +282,7 @@ return apply_filters('tainacan-admin-i18n',[
'info_date' => __( 'Date: ', 'tainacan' ), 'info_date' => __( 'Date: ', 'tainacan' ),
'info_not_saved' => __( 'Not saved ', '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_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_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_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' ), '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_no_events' => __( 'No events', 'tainacan' ),
'info_logs_before' => __( 'Before updating', 'tainacan' ), 'info_logs_before' => __( 'Before updating', 'tainacan' ),
'info_logs_after' => __( 'What was updated', '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_there_is_no_filter' => __( 'There is no filter here yet.', 'tainacan' ),
'info_changes' => __( 'Changes', 'tainacan' ), 'info_changes' => __( 'Changes', 'tainacan' ),
'info_possible_external_sources' => __( 'Possible external sources: CSV, Instagram, Youtube, etc.', '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_create_metadata' => __( 'Click or Drag and Drop Metadata Types here for creating a new Metadata.', 'tainacan' ),
'info_choose_your_metadata' => __( 'Choose your metadata.', 'tainacan' ), 'info_choose_your_metadata' => __( 'Choose your metadata.', 'tainacan' ),
// Tainacan Field Types // Tainacan Metadatum Types
'tainacan-text' => __( 'Text', 'tainacan' ), 'tainacan-text' => __( 'Text', 'tainacan' ),
'tainacan-textarea' => __( 'Text area', 'tainacan' ), 'tainacan-textarea' => __( 'Text area', 'tainacan' ),
'tainacan-date' => __( 'Date', 'tainacan' ), 'tainacan-date' => __( 'Date', 'tainacan' ),

View File

@ -86,11 +86,11 @@ class REST_Controller extends \WP_REST_Controller {
]; ];
$meta_query = [ $meta_query = [
'key' => 'key', 'key' => 'key',
'value' => 'value', 'value' => 'value',
'compare' => 'compare', 'compare' => 'compare',
'relation' => 'relation', 'relation' => 'relation',
'fieldtype' => 'type', 'metadatumtype' => 'type',
]; ];
$date_query = [ $date_query = [
@ -109,11 +109,11 @@ class REST_Controller extends \WP_REST_Controller {
]; ];
$tax_query = [ $tax_query = [
'taxonomy' => 'taxonomy', 'taxonomy' => 'taxonomy',
'field' => 'field', 'metadatum' => 'field',
'terms' => 'terms', 'terms' => 'terms',
'operator' => 'operator', 'operator' => 'operator',
'relation' => 'relation', 'relation' => 'relation',
]; ];
$args = []; $args = [];
@ -140,12 +140,12 @@ class REST_Controller extends \WP_REST_Controller {
/** /**
* @param $data * @param $data
* @param $field_name * @param $metadatum_name
* @param $request * @param $request
* *
* @return \WP_Error * @return \WP_Error
*/ */
function gt_user_meta( $data, $field_name, $request ) { function gt_user_meta( $data, $metadatum_name, $request ) {
if( $data['id'] ){ if( $data['id'] ){
$user_meta = get_user_meta( $data['id'] ); $user_meta = get_user_meta( $data['id'] );
} }
@ -164,19 +164,19 @@ class REST_Controller extends \WP_REST_Controller {
/** /**
* @param $meta * @param $meta
* @param $user * @param $user
* @param $field_name * @param $metadatum_name
* *
* @param $request * @param $request
* *
* @return mixed|\WP_Error * @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 ) { if ( !$user->ID ) {
return new \WP_Error( 'No user found', 'No user found', array( 'status' => 404 ) ); return new \WP_Error( 'No user found', 'No user found', array( 'status' => 404 ) );
} }
$user_id = $user->ID; $user_id = $user->ID;
$metas = $field_name === 'meta' ? $meta : []; $metas = $metadatum_name === 'meta' ? $meta : [];
$map = [ $map = [
'metakey', 'metakey',
@ -244,16 +244,16 @@ class REST_Controller extends \WP_REST_Controller {
foreach ( $request_meta_query as $index1 => $a ) { foreach ( $request_meta_query as $index1 => $a ) {
// handle core field // handle core metadatum
if( is_array($a) && array_key_exists("key", $a) ){ if( is_array($a) && array_key_exists("key", $a) ){
$field = new \Tainacan\Entities\Field($a['key']); $metadatum = new \Tainacan\Entities\Metadatum($a['key']);
if( strpos( $field->get_field_type(), 'Core_Title') !== false ){ if( strpos( $metadatum->get_metadatum_type(), 'Core_Title') !== false ){
$args[ 'post_title_in' ] = [ $args[ 'post_title_in' ] = [
'relation' => ( isset( $request_meta_query['relation']) ) ? $request_meta_query['relation'] : 'AND' , 'relation' => ( isset( $request_meta_query['relation']) ) ? $request_meta_query['relation'] : 'AND' ,
'value' => ( is_array( $a['value'] ) ) ? $a['value'] : [$a['value']] 'value' => ( is_array( $a['value'] ) ) ? $a['value'] : [$a['value']]
]; ];
continue; 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' ] = [ $args[ 'post_content_in' ] = [
'relation' => ( isset( $request_meta_query['relation']) ) ? $request_meta_query['relation'] : 'AND' , 'relation' => ( isset( $request_meta_query['relation']) ) ? $request_meta_query['relation'] : 'AND' ,
'value' => ( is_array( $a['value'] ) ) ? $a['value'] : [$a['value']] '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.'), 'description' => __('OR or AND, how the sub-arrays should be compared.'),
'default' => 'AND', 'default' => 'AND',
), ),
'fieldtype' => array( 'metadatumtype' => array(
'type' => 'string', '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.'), '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', 'type' => 'string',
'description' => __('The taxonomy data base identifier.') 'description' => __('The taxonomy data base identifier.')
), ),
'field' => array( 'metadatum' => array(
'type' => 'string', 'type' => 'string',
'description' => __('Select taxonomy term by. Possible values are term_id, name, slug or term_taxonomy_id. Default value is term_id.') 'description' => __('Select taxonomy term by. Possible values are term_id, name, slug or term_taxonomy_id. Default value is term_id.')
), ),

View File

@ -11,7 +11,7 @@ class REST_Export_Controller extends REST_Controller {
private $item_metadata_repository; private $item_metadata_repository;
private $items_repository; private $items_repository;
private $collection_repository; private $collection_repository;
private $field_repository; private $metadatum_repository;
public function __construct() { public function __construct() {
$this->rest_base = 'export'; $this->rest_base = 'export';
@ -25,20 +25,20 @@ class REST_Export_Controller extends REST_Controller {
* @throws \Exception * @throws \Exception
*/ */
public function init_objects() { 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_metadata_repository = Repositories\Item_Metadata::get_instance();
$this->items_repository = Repositories\Items::get_instance(); $this->items_repository = Repositories\Items::get_instance();
$this->collection_repository = Repositories\Collections::get_instance(); $this->collection_repository = Repositories\Collections::get_instance();
} }
/** /**
* If POST on field/collection/<collection_id>, then * If POST on metadatum/collection/<collection_id>, then
* a field will be created in matched collection and all your item will receive this field * 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 * id body of requisition
* *
* Both of GETs return the field of matched objects * Both of GETs return the metadatum of matched objects
* *
* @throws \Exception * @throws \Exception
*/ */
@ -82,15 +82,15 @@ class REST_Export_Controller extends REST_Controller {
*/ */
public function get_item( $request ) { public function get_item( $request ) {
/*$collection_id = $request['collection_id']; /*$collection_id = $request['collection_id'];
$field_id = $request['field_id']; $metadatum_id = $request['metadatum_id'];
if($request['fetch'] === 'all_field_values'){ if($request['fetch'] === 'all_metadatum_values'){
$results = $this->field_repository->fetch_all_field_values($collection_id, $field_id); $results = $this->metadatum_repository->fetch_all_metadatum_values($collection_id, $metadatum_id);
return new \WP_REST_Response($results, 200); 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); $prepared_item = $this->prepare_item_for_response($result, $request);
return new \WP_REST_Response(apply_filters('tainacan-rest-response', $prepared_item, $request), 200);*/ 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 * @return array|\WP_Error|\WP_REST_Response
*/ */
public function prepare_item_for_response( $item, $request ) { public function prepare_item_for_response( $item, $request ) {
$items_metadata = $item->get_fields(); $items_metadata = $item->get_metadata();
$prepared_item = []; $prepared_item = [];

View File

@ -10,8 +10,8 @@ class REST_Filters_Controller extends REST_Controller {
private $collection; private $collection;
private $collection_repository; private $collection_repository;
private $field; private $metadatum;
private $field_repository; private $metadatum_repository;
private $filter_repository; private $filter_repository;
@ -31,13 +31,13 @@ class REST_Filters_Controller extends REST_Controller {
$this->collection = new Entities\Collection(); $this->collection = new Entities\Collection();
$this->collection_repository = Repositories\Collections::get_instance(); $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(); $this->filter_repository = Repositories\Filters::get_instance();
} }
public function register_routes() { 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( array(
'methods' => \WP_REST_Server::CREATABLE, 'methods' => \WP_REST_Server::CREATABLE,
'callback' => array($this, 'create_item'), 'callback' => array($this, 'create_item'),
@ -131,30 +131,30 @@ class REST_Filters_Controller extends REST_Controller {
$filter_obj->set($attribute, $value); $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']; $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_collection_id( $collection_id );
$filter_obj->set_field( $field_id ); $filter_obj->set_metadatum( $metadatum_id );
} elseif (isset($request['collection_id'])){ } elseif (isset($request['collection_id'])){
$collection_id = $request['collection_id']; $collection_id = $request['collection_id'];
$filter_obj->set_collection_id( $collection_id ); $filter_obj->set_collection_id( $collection_id );
if(!isset($body['field'])){ if(!isset($body['metadatum'])){
throw new \InvalidArgumentException('You need provide a field id'); throw new \InvalidArgumentException('You need provide a metadatum id');
} }
$filter_obj->set_field($body['field']); $filter_obj->set_metadatum($body['metadatum']);
} else { } else {
$filter_obj->set_collection_id( 'filter_in_repository' ); $filter_obj->set_collection_id( 'filter_in_repository' );
if(!isset($body['field'])){ if(!isset($body['metadatum'])){
throw new \InvalidArgumentException('You need provide a field id'); 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); $filter_obj->set_filter_type($filter_type);
@ -197,11 +197,11 @@ class REST_Filters_Controller extends REST_Controller {
* @throws \Exception * @throws \Exception
*/ */
public function create_item_permissions_check( $request ) { public function create_item_permissions_check( $request ) {
if(isset($request['collection_id']) && isset($request['field_id'])) { if(isset($request['collection_id']) && isset($request['metadatum_id'])) {
$metadata = $this->field_repository->fetch( $request['field_id'] ); $metadata = $this->metadatum_repository->fetch( $request['metadatum_id'] );
$collection = $this->collection_repository->fetch( $request['collection_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(); 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());
} }
/** /**

View File

@ -7,11 +7,11 @@ use Tainacan\Entities;
use Tainacan\Repositories; use Tainacan\Repositories;
class REST_Item_Metadata_Controller extends REST_Controller { class REST_Item_Metadata_Controller extends REST_Controller {
private $field; private $metadatum;
private $item_metadata_repository; private $item_metadata_repository;
private $item_repository; private $item_repository;
private $collection_repository; private $collection_repository;
private $field_repository; private $metadatum_repository;
public function __construct() { public function __construct() {
$this->rest_base = 'metadata'; $this->rest_base = 'metadata';
@ -23,24 +23,24 @@ class REST_Item_Metadata_Controller extends REST_Controller {
* Initialize objects after post_type register * Initialize objects after post_type register
*/ */
public function init_objects() { public function init_objects() {
$this->field = new Entities\Field(); $this->metadatum = new Entities\Metadatum();
$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_metadata_repository = Repositories\Item_Metadata::get_instance();
$this->item_repository = Repositories\Items::get_instance(); $this->item_repository = Repositories\Items::get_instance();
$this->collection_repository = Repositories\Collections::get_instance(); $this->collection_repository = Repositories\Collections::get_instance();
} }
/** /**
* If POST on field/collection/<collection_id>, then * If POST on metadatum/collection/<collection_id>, then
* a field will be created in matched collection and all your item will receive this field * 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 * 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() { 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(
array( array(
'methods' => \WP_REST_Server::EDITABLE, '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(
array( array(
'methods' => \WP_REST_Server::READABLE, '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'), '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){ foreach ($meta as $key => $value){
$set_ = 'set_' . $key; $set_ = 'set_' . $key;
$this->field->$set_($value); $this->metadatum->$set_($value);
} }
$collection = new Entities\Collection($request[1]); $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); $item = $this->item_repository->fetch($item_id);
$items_metadata = $item->get_fields(); $items_metadata = $item->get_metadata();
$prepared_item = []; $prepared_item = [];
foreach ($items_metadata as $item_metadata){ foreach ($items_metadata as $item_metadata){
$index = array_push($prepared_item, $this->prepare_item_for_response($item_metadata, $request)); $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); 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 * @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']; $item_id = $request['item_id'];
$field_id = $request['metadata_id']; $metadatum_id = $request['metadatum_id'];
$item = $this->item_repository->fetch($item_id); $item = $this->item_repository->fetch($item_id);
$items_metadata = $item->get_fields(); $items_metadata = $item->get_metadata();
$prepared_item = ''; $prepared_item = '';
foreach ($items_metadata as $item_metadata){ foreach ($items_metadata as $item_metadata){
$field = $item_metadata->get_field(); $metadatum = $item_metadata->get_metadatum();
if($field->get_id() == $field_id) { if($metadatum->get_id() == $metadatum_id) {
$prepared_item = $this->prepare_item_for_response($item_metadata, $request); $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) { if($body) {
$item_id = $request['item_id']; $item_id = $request['item_id'];
$field_id = $request['metadata_id']; $metadatum_id = $request['metadatum_id'];
$value = $body['values']; $value = $body['values'];
$item = $this->item_repository->fetch( $item_id ); $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()) { if($item_metadata->is_multiple()) {
$item_metadata->set_value( $value ); $item_metadata->set_value( $value );
@ -202,18 +202,18 @@ class REST_Item_Metadata_Controller extends REST_Controller {
if ( $item_metadata->validate() ) { if ( $item_metadata->validate() ) {
if($item->can_edit()) { 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 = $this->prepare_item_for_response($metadatum_updated, $request);
$prepared_item['field']['field_type_object'] = $this->prepare_item_for_response($field_updated->get_field()->get_field_type_object(), $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 ); $log = $this->item_metadata_repository->suggest( $item_metadata );
$prepared_item = $log->_toArray(); $prepared_item = $log->_toArray();
} }
else { else {
return new \WP_REST_Response( [ return new \WP_REST_Response( [
'error_message' => __( 'The metadata does not accept suggestions', 'tainacan' ), 'error_message' => __( 'The metadatum does not accept suggestions', 'tainacan' ),
], 400 ); ], 400 );
} }
@ -248,9 +248,9 @@ class REST_Item_Metadata_Controller extends REST_Controller {
return $item->can_edit(); return $item->can_edit();
} }
else { else {
$field_id = $request['metadata_id']; $metadatum_id = $request['metadatum_id'];
$field = $this->field_repository->fetch( $field_id ); $metadatum = $this->metadatum_repository->fetch( $metadatum_id );
return 'publish' === $field->get_status() && $field->get_accept_suggestion(); return 'publish' === $metadatum->get_status() && $metadatum->get_accept_suggestion();
} }
} }

View File

@ -109,22 +109,22 @@ class REST_Items_Controller extends REST_Controller {
* @return mixed * @return mixed
*/ */
private function add_metadata_to_item($item_object, $item_array, $args = []){ 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){ foreach($item_metadata as $index => $me){
$field = $me->get_field(); $metadatum = $me->get_metadatum();
$slug = $field->get_slug(); $slug = $metadatum->get_slug();
$item_metadata_array = $me->_toArray(); $item_metadata_array = $me->_toArray();
$item_array['metadata'][ $slug ]['name'] = $field->get_name(); $item_array['metadata'][ $slug ]['name'] = $metadatum->get_name();
if($field->get_field_type_object()->get_primitive_type() === 'date') { if($metadatum->get_metadatum_type_object()->get_primitive_type() === 'date') {
$item_array['metadata'][ $slug ]['date_i18n'] = $item_metadata_array['date_i18n']; $item_array['metadata'][ $slug ]['date_i18n'] = $item_metadata_array['date_i18n'];
} else { } else {
$item_array['metadata'][ $slug ]['value'] = $item_metadata_array['value']; $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_html'] = $item_metadata_array['value_as_html'];
$item_array['metadata'][ $slug ]['value_as_string'] = $item_metadata_array['value_as_string']; $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; return $item_array;
@ -238,11 +238,11 @@ class REST_Items_Controller extends REST_Controller {
ob_start(); ob_start();
global $wp_query, $view_mode_displayed_fields; global $wp_query, $view_mode_displayed_metadata;
$wp_query = $items; $wp_query = $items;
$displayed_metadata = array_map(function($el) { return (int) $el; }, $request['fetch_only']['meta']); $displayed_metadata = array_map(function($el) { return (int) $el; }, $request['fetch_only']['meta']);
$view_mode_displayed_fields = $request['fetch_only']; $view_mode_displayed_metadata = $request['fetch_only'];
$view_mode_displayed_fields['meta'] = $displayed_metadata; $view_mode_displayed_metadata['meta'] = $displayed_metadata;
include $view_mode['template']; include $view_mode['template'];

View File

@ -6,14 +6,14 @@ use \Tainacan\API\REST_Controller;
use Tainacan\Entities; use Tainacan\Entities;
use Tainacan\Repositories; use Tainacan\Repositories;
class REST_Fields_Controller extends REST_Controller { class REST_Metadata_Controller extends REST_Controller {
private $item_metadata_repository; private $item_metadata_repository;
private $item_repository; private $item_repository;
private $collection_repository; private $collection_repository;
private $field_repository; private $metadatum_repository;
public function __construct() { public function __construct() {
$this->rest_base = 'fields'; $this->rest_base = 'metadata';
parent::__construct(); parent::__construct();
add_action('init', array(&$this, 'init_objects'), 11); add_action('init', array(&$this, 'init_objects'), 11);
} }
@ -24,25 +24,25 @@ class REST_Fields_Controller extends REST_Controller {
* @throws \Exception * @throws \Exception
*/ */
public function init_objects() { 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_metadata_repository = Repositories\Item_Metadata::get_instance();
$this->item_repository = Repositories\Items::get_instance(); $this->item_repository = Repositories\Items::get_instance();
$this->collection_repository = Repositories\Collections::get_instance(); $this->collection_repository = Repositories\Collections::get_instance();
} }
/** /**
* If POST on field/collection/<collection_id>, then * If POST on metadatum/collection/<collection_id>, then
* a field will be created in matched collection and all your item will receive this field * 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 * id body of requisition
* *
* Both of GETs return the field of matched objects * Both of GETs return the metadatum of matched objects
* *
* @throws \Exception * @throws \Exception
*/ */
public function register_routes() { 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(
array( array(
'methods' => \WP_REST_Server::EDITABLE, '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( array(
// ENDPOINT Z. // ENDPOINT Z.
array( array(
@ -127,28 +127,28 @@ class REST_Fields_Controller extends REST_Controller {
*/ */
public function get_item( $request ) { public function get_item( $request ) {
$collection_id = isset($request['collection_id']) ? $request['collection_id'] : false; $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) { 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 { } 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); return new \WP_REST_Response($results, 200);
} elseif($request['fetch'] === 'all_field_values') { } elseif($request['fetch'] === 'all_metadatum_values') {
if($collection_id) { 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 { } 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); 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); 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; return true;
} }
} elseif($request['field_id']) { } elseif($request['metadatum_id']) {
$field = $this->field_repository->fetch($request['field_id']); $metadatum = $this->metadatum_repository->fetch($request['metadatum_id']);
if ( $field instanceof Entities\Field ) { if ( $metadatum instanceof Entities\Metadatum ) {
if ( $request['context'] === 'edit' && ! $field->can_read() ) { if ( $request['context'] === 'edit' && ! $metadatum->can_read() ) {
return false; return false;
} }
@ -196,22 +196,22 @@ class REST_Fields_Controller extends REST_Controller {
* @throws \Exception * @throws \Exception
*/ */
public function prepare_item_for_database( $request, $collection_id = null ) { public function prepare_item_for_database( $request, $collection_id = null ) {
$field = new Entities\Field(); $metadatum = new Entities\Metadatum();
$meta = json_decode( $request, true ); $meta = json_decode( $request, true );
foreach ( $meta as $key => $value ) { foreach ( $meta as $key => $value ) {
$set_ = 'set_' . $key; $set_ = 'set_' . $key;
$field->$set_( $value ); $metadatum->$set_( $value );
} }
if($collection_id) { if($collection_id) {
$collection = new Entities\Collection( $collection_id ); $collection = new Entities\Collection( $collection_id );
$field->set_collection( $collection ); $metadatum->set_collection( $collection );
} else { } 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()) { 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); return new \WP_REST_Response($response, 201);
} else { } else {
return new \WP_REST_Response([ return new \WP_REST_Response([
'error_message' => __('One or more values are invalid.', 'tainacan'), 'error_message' => __('One or more values are invalid.', 'tainacan'),
'errors' => $prepared->get_errors(), 'errors' => $prepared->get_errors(),
'field' => $this->prepare_item_for_response($prepared, $request), 'metadatum' => $this->prepare_item_for_response($prepared, $request),
], 400); ], 400);
} }
} elseif (!empty($request->get_body())) { } elseif (!empty($request->get_body())) {
@ -251,16 +251,16 @@ class REST_Fields_Controller extends REST_Controller {
} }
if ( $prepared->validate() ) { 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); return new \WP_REST_Response($response, 201);
} else { } else {
return new \WP_REST_Response([ return new \WP_REST_Response([
'error_message' => __('One or more values are invalid.', 'tainacan'), 'error_message' => __('One or more values are invalid.', 'tainacan'),
'errors' => $prepared->get_errors(), 'errors' => $prepared->get_errors(),
'field' => $this->prepare_item_for_response($prepared, $request), 'metadatum' => $this->prepare_item_for_response($prepared, $request),
], 400); ], 400);
} }
@ -284,7 +284,7 @@ class REST_Fields_Controller extends REST_Controller {
return $this->collection_repository->can_edit( new Entities\Collection() ); 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)){ if(!empty($item)){
$item_arr = $item->_toArray(); $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'){ if($request['context'] === 'edit'){
$item_arr['current_user_can_edit'] = $item->can_edit(); $item_arr['current_user_can_edit'] = $item->can_edit();
ob_start(); ob_start();
$item->get_field_type_object()->form(); $item->get_metadatum_type_object()->form();
$form = ob_get_clean(); $form = ob_get_clean();
$item_arr['edit_form'] = $form; $item_arr['edit_form'] = $form;
$item_arr['enabled'] = $item->get_enabled_for_collection(); $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 ); $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 { } else {
$args = [ $args = [
'meta_query' => [ '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 = []; $prepared_item = [];
@ -362,7 +362,7 @@ class REST_Fields_Controller extends REST_Controller {
* @throws \Exception * @throws \Exception
*/ */
public function get_items_permissions_check( $request ) { 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; return false;
} }
@ -375,11 +375,11 @@ class REST_Fields_Controller extends REST_Controller {
* @return \WP_Error|\WP_REST_Response * @return \WP_Error|\WP_REST_Response
*/ */
public function delete_item( $request ) { 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); 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)){ if(!empty($body)){
$attributes = []; $attributes = [];
$field_id = $request['field_id']; $metadatum_id = $request['metadatum_id'];
foreach ($body as $att => $value){ foreach ($body as $att => $value){
$attributes[$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'); $error_message = __('Metadata with this ID was not found', 'tainacan');
if($field){ if($metadatum){
// These conditions are for verify if endpoints are used correctly // 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'); $error_message = __('This metadata is not a default metadata', 'tainacan');
return new \WP_REST_Response( [ return new \WP_REST_Response( [
'error_message' => $error_message, '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'); $error_message = __('This metadata is not a collection metadata', 'tainacan');
return new \WP_REST_Response( [ return new \WP_REST_Response( [
'error_message' => $error_message, '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()){ 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); $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([ return new \WP_REST_Response([
'error_message' => __('One or more values are invalid.', 'tainacan'), 'error_message' => __('One or more values are invalid.', 'tainacan'),
'errors' => $prepared_metadata->get_errors(), 'errors' => $prepared_metadata->get_errors(),
'metadata' => $this->prepare_item_for_response($prepared_metadata, $request) 'metadatum' => $this->prepare_item_for_response($prepared_metadata, $request)
], 400); ], 400);
} }
return new \WP_REST_Response( [ return new \WP_REST_Response( [
'error_message' => $error_message, '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 ) { public function get_collection_params( $object_name = null ) {
$query_params['context']['default'] = 'view'; $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( $query_params['name'] = array(
'description' => __('Limits the result set to metadata with a specific name'), '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'] = [ $endpoint_args['fetch'] = [
'type' => 'string', 'type' => 'string',
'description' => __('Fetch all content of a metadata within a collection'), 'description' => __('Fetch all content of a metadata within a collection'),
'enum' => ['all_field_values'] 'enum' => ['all_metadatum_values']
]; ];
$endpoint_args['context'] = array( $endpoint_args['context'] = array(
'type' => 'string', 'type' => 'string',
@ -531,13 +531,13 @@ class REST_Fields_Controller extends REST_Controller {
'items' => array( 'view, edit' ) 'items' => array( 'view, edit' )
); );
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) { } 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){ foreach ($map as $mapped => $value){
$set_ = 'set_'. $mapped; $set_ = 'set_'. $mapped;
// Show only args that has a method set // 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]); unset($map[$mapped]);
} }
} }

View File

@ -4,13 +4,13 @@ namespace Tainacan\API\EndPoints;
use \Tainacan\API\REST_Controller; 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() { public function __construct() {
$this->rest_base = 'field-mappers'; $this->rest_base = 'metadatum-mappers';
parent::__construct(); parent::__construct();
} }
@ -34,9 +34,9 @@ class REST_Field_Mappers_Controller extends REST_Controller {
*/ */
public function prepare_item_for_response( $mapper, $request ) { 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 ) { public function get_items( $request ) {
$Tainacan_Exposers = \Tainacan\Exposers\Exposers::get_instance(); $Tainacan_Exposers = \Tainacan\Exposers\Exposers::get_instance();
$field_mappers = $Tainacan_Exposers->get_mappers( 'OBJECT' ); $metadatum_mappers = $Tainacan_Exposers->get_mappers( 'OBJECT' );
$prepared = []; $prepared = [];
foreach ($field_mappers as $field_mapper){ foreach ($metadatum_mappers as $metadatum_mapper){
array_push($prepared, $this->prepare_item_for_response($field_mapper, $request)); array_push($prepared, $this->prepare_item_for_response($metadatum_mapper, $request));
} }
return new \WP_REST_Response($prepared, 200); return new \WP_REST_Response($prepared, 200);

View File

@ -4,13 +4,13 @@ namespace Tainacan\API\EndPoints;
use \Tainacan\API\REST_Controller; 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() { public function __construct() {
$this->rest_base = 'field-types'; $this->rest_base = 'metadatum-types';
parent::__construct(); parent::__construct();
} }
@ -22,7 +22,7 @@ class REST_Field_Types_Controller extends REST_Controller {
'callback' => array($this, 'get_items'), 'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check'), 'permission_callback' => array($this, 'get_items_permissions_check'),
'args' => [ 'args' => [
'field-type' => [ 'metadatum-type' => [
'description' => __('The structure of objects returned.'), 'description' => __('The structure of objects returned.'),
'items' => [ 'items' => [
'errors' => [ 'errors' => [
@ -67,13 +67,13 @@ class REST_Field_Types_Controller extends REST_Controller {
* @return mixed|\WP_Error|\WP_REST_Response * @return mixed|\WP_Error|\WP_REST_Response
*/ */
public function prepare_item_for_response( $item, $request ) { public function prepare_item_for_response( $item, $request ) {
$name = "\Tainacan\Field_Types\\$item"; $name = "\Tainacan\Metadatum_Types\\$item";
$field_type = new $name(); $metadatum_type = new $name();
$field_arr = $field_type->_toArray(); $metadatum_arr = $metadatum_type->_toArray();
$field_arr['name'] = $item; $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 * @return \WP_Error|\WP_REST_Response
*/ */
public function get_items( $request ) { 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 = []; $prepared = [];
foreach ($field_types as $field_type){ foreach ($metadatum_types as $metadatum_type){
array_push($prepared, $this->prepare_item_for_response($field_type, $request)); array_push($prepared, $this->prepare_item_for_response($metadatum_type, $request));
} }
return new \WP_REST_Response($prepared, 200); return new \WP_REST_Response($prepared, 200);

View File

@ -1,20 +1,20 @@
<?php <?php
const TAINACAN_REST_NAMESPACE = 'tainacan/v2'; const TAINACAN_REST_NAMESPACE = 'tainacan/v2';
//$rest_controller = new \Tainacan\API\REST_Controller(); //$rest_controller = new \Tainacan\API\REST_Controller();
$rest_collections_controller = new \Tainacan\API\EndPoints\REST_Collections_Controller(); $rest_collections_controller = new \Tainacan\API\EndPoints\REST_Collections_Controller();
$rest_items_controller = new \Tainacan\API\EndPoints\REST_Items_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_taxonomies_controller = new \Tainacan\API\EndPoints\REST_Taxonomies_Controller();
$rest_terms_controller = new \Tainacan\API\EndPoints\REST_Terms_Controller(); $rest_terms_controller = new \Tainacan\API\EndPoints\REST_Terms_Controller();
$rest_filters_controller = new \Tainacan\API\EndPoints\REST_Filters_Controller(); $rest_filters_controller = new \Tainacan\API\EndPoints\REST_Filters_Controller();
$rest_item_metadata_controller = new \Tainacan\API\EndPoints\REST_Item_Metadata_Controller(); $rest_item_metadata_controller = new \Tainacan\API\EndPoints\REST_Item_Metadata_Controller();
$rest_logs_controller = new \Tainacan\API\EndPoints\REST_Logs_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(); $rest_filter_types_controller = new \Tainacan\API\EndPoints\REST_Filter_Types_Controller();
new \Tainacan\API\EndPoints\REST_Export_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 // Add here other endpoints imports
?> ?>

View File

@ -47,7 +47,7 @@ class Capabilities {
"read" "read"
] ]
], ],
"tainacan-field"=> [ "tainacan-metadatum"=> [
"administrator"=> [ "administrator"=> [
"delete_posts", "delete_posts",
"delete_private_posts", "delete_private_posts",

View File

@ -27,7 +27,7 @@ class Collection extends Entity {
$columns, $columns,
$default_view_mode, $default_view_mode,
$enabled_view_modes, $enabled_view_modes,
$fields_order, $metadata_order,
$filters_order, $filters_order,
$enable_cover_page, $enable_cover_page,
$cover_page_id, $cover_page_id,
@ -342,8 +342,8 @@ class Collection extends Entity {
* *
* @return string * @return string
*/ */
function get_default_displayed_fields() { function get_default_displayed_metadata() {
return $this->get_mapped_property( 'default_displayed_fields' ); 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 * @return string
*/ */
function get_fields_order() { function get_metadata_order() {
return $this->get_mapped_property( 'fields_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 * @throws \Exception
*/ */
function get_fields() { function get_metadata() {
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance(); $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() { function get_core_metadata() {
$repo = \Tainacan\Repositories\Fields::get_instance(); $repo = \Tainacan\Repositories\Metadata::get_instance();
return $repo->fetch_by_collection($this, [ return $repo->fetch_by_collection($this, [
'meta_query' => [ 'meta_query' => [
[ [
'key' => 'field_type', 'key' => 'metadatum_type',
'value' => ['Tainacan\Field_Types\Core_Title', 'Tainacan\Field_Types\Core_Description'], 'value' => ['Tainacan\Metadatum_Types\Core_Title', 'Tainacan\Metadatum_Types\Core_Description'],
'compare' => 'IN' '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() { function get_core_title_metadatum() {
$repo = \Tainacan\Repositories\Fields::get_instance(); $repo = \Tainacan\Repositories\Metadata::get_instance();
$results = $repo->fetch_by_collection($this, [ $results = $repo->fetch_by_collection($this, [
'meta_query' => [ 'meta_query' => [
[ [
'key' => 'field_type', 'key' => 'metadatum_type',
'value' => 'Tainacan\Field_Types\Core_Title', 'value' => 'Tainacan\Metadatum_Types\Core_Title',
] ]
], ],
'posts_per_page' => 1 'posts_per_page' => 1
], 'OBJECT'); ], '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 $results[0];
} }
return false; 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() { function get_core_description_metadatum() {
$repo = \Tainacan\Repositories\Fields::get_instance(); $repo = \Tainacan\Repositories\Metadata::get_instance();
$results = $repo->fetch_by_collection($this, [ $results = $repo->fetch_by_collection($this, [
'meta_query' => [ 'meta_query' => [
[ [
'key' => 'field_type', 'key' => 'metadatum_type',
'value' => 'Tainacan\Field_Types\Core_Description', 'value' => 'Tainacan\Metadatum_Types\Core_Description',
] ]
], ],
'posts_per_page' => 1 'posts_per_page' => 1
], 'OBJECT'); ], '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 $results[0];
} }
return false; return false;
@ -611,8 +611,8 @@ class Collection extends Entity {
* *
* @return void * @return void
*/ */
function set_default_displayed_fields( $value ) { function set_default_displayed_metadata( $value ) {
$this->set_mapped_property( 'default_displayed_fields', $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 * @param [string] $value
* *
* @return void * @return void
*/ */
function set_fields_order( $value ) { function set_metadata_order( $value ) {
$this->set_mapped_property( 'fields_order', $value ); $this->set_mapped_property( 'metadata_order', $value );
} }
/** /**

View File

@ -15,7 +15,7 @@ class Filter extends Entity {
$description, $description,
$order, $order,
$color, $color,
$field, $metadatum,
$filter_type, $filter_type,
$filter_type_options; $filter_type_options;
@ -39,11 +39,11 @@ class Filter extends Entity {
*/ */
public function _toArray(){ public function _toArray(){
$filter_array = parent::_toArray(); $filter_array = parent::_toArray();
$field_id = $filter_array['field']; $metadatum_id = $filter_array['metadatum'];
$filter_array['field'] = []; $filter_array['metadatum'] = [];
$filter_array['field']['field_id'] = $field_id; $filter_array['metadatum']['metadatum_id'] = $metadatum_id;
$filter_array['field']['field_name'] = $this->get_field()->get_name(); $filter_array['metadatum']['metadatum_name'] = $this->get_metadatum()->get_name();
return $filter_array; return $filter_array;
} }
@ -83,14 +83,14 @@ class Filter extends Entity {
} }
/** /**
* Return the field * Return the metadatum
* *
* @return Field * @return Metadatum
* @throws \Exception * @throws \Exception
*/ */
function get_field() { function get_metadatum() {
$id = $this->get_mapped_property('field'); $id = $this->get_mapped_property('metadatum');
return new Field( $id ); 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 * @return void
*/ */
function set_field( $value ){ function set_metadatum( $value ){
$id = ( $value instanceof Field ) ? $value->get_id() : $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 * 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() { public function get_enabled_for_collection() {
@ -207,7 +207,7 @@ class Filter extends Entity {
/** /**
* {@inheritdoc } * {@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 * @return bool valid or not
* @throws \Exception * @throws \Exception
@ -228,11 +228,11 @@ class Filter extends Entity {
} }
if (!is_array($is_valid)) { 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) { foreach ($is_valid as $metadatum => $message) {
$this->add_error($field, $message); $this->add_error($metadatum, $message);
} }
return false; return false;

View File

@ -5,7 +5,7 @@ namespace Tainacan\Entities;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/** /**
* Represents the Item Field Entity * Represents the Item Metadatum Entity
*/ */
class Item_Metadata_Entity extends Entity { class Item_Metadata_Entity extends Entity {
protected static $post_type = false; protected static $post_type = false;
@ -18,7 +18,7 @@ class Item_Metadata_Entity extends Entity {
protected protected
$item, $item,
$field, $metadatum,
$parent_meta_id, $parent_meta_id,
$meta_id, $meta_id,
$has_value, $has_value,
@ -27,13 +27,13 @@ class Item_Metadata_Entity extends Entity {
/** /**
* *
* @param Item $item Item 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 * @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_item($item);
$this->set_field($field); $this->set_metadatum($metadatum);
if (!is_null($meta_id) && is_int($meta_id)) { if (!is_null($meta_id) && is_int($meta_id)) {
$this->set_meta_id($meta_id); $this->set_meta_id($meta_id);
@ -51,10 +51,10 @@ class Item_Metadata_Entity extends Entity {
* @return string * @return string
*/ */
public function get_value_as_html(){ public function get_value_as_html(){
$field = $this->get_field(); $metadatum = $this->get_metadatum();
if (is_object($field)) { if (is_object($metadatum)) {
$fto = $field->get_field_type_object(); $fto = $metadatum->get_metadatum_type_object();
if (is_object($fto)) { if (is_object($fto)) {
if ( method_exists($fto, 'get_value_as_html') ) { 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_html'] = $this->get_value_as_html();
$as_array['value_as_string'] = $this->get_value_as_string(); $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['date_i18n'] = $this->get_date_i18n($this->get_value_as_string());
} }
$as_array['item'] = $this->get_item()->_toArray(); $as_array['item'] = $this->get_item()->_toArray();
$as_array['field'] = $this->get_field()->_toArray(); $as_array['metadatum'] = $this->get_metadatum()->_toArray();
return $as_array; 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 * @param [integer | string] $value
* @return void * @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 * @return void
*/ */
function set_field(Field $field = null) { function set_metadatum(Metadatum $metadatum = null) {
$this->field = $field; $this->metadatum = $metadatum;
} }
/** /**
* Set the specific meta ID for this metadata. * Set the specific meta ID for this metadata.
* *
* When this value is set, get_value() will use it to fetch the value from * 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 * @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)) { if (is_int($meta_id)) {
$this->meta_id = $meta_id; $this->meta_id = $meta_id;
return true; 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; 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] * @param [type] $parent_meta_id [description]
*/ */
@ -211,7 +211,7 @@ class Item_Metadata_Entity extends Entity {
if (is_int($parent_meta_id)) { if (is_int($parent_meta_id)) {
$this->parent_meta_id = $parent_meta_id; $this->parent_meta_id = $parent_meta_id;
return true; 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; 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() { function get_metadatum() {
return $this->field; return $this->metadatum;
} }
/** /**
* Return the meta_id * Return the meta_id
* *
* @return Field * @return Metadatum
*/ */
function get_meta_id() { function get_meta_id() {
return isset($this->meta_id) ? $this->meta_id : null; return isset($this->meta_id) ? $this->meta_id : null;
@ -246,14 +246,14 @@ class Item_Metadata_Entity extends Entity {
/** /**
* Return the meta_id * Return the meta_id
* *
* @return Field * @return Metadatum
*/ */
function get_parent_meta_id() { function get_parent_meta_id() {
return isset($this->parent_meta_id) ? $this->parent_meta_id : 0; return isset($this->parent_meta_id) ? $this->parent_meta_id : 0;
} }
/** /**
* Return the field value * Return the metadatum value
* *
* @return string | integer * @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 * @return boolean
*/ */
function is_multiple() { 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 * @return boolean
*/ */
function is_collection_key() { 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 * @return boolean
*/ */
function is_required() { 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() { function validate() {
$value = $this->get_value(); $value = $this->get_value();
$field = $this->get_field(); $metadatum = $this->get_metadatum();
$item = $this->get_item(); $item = $this->get_item();
if (empty($value) && $this->is_required()) { 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; return false;
} }
$classFieldType = $field->get_field_type_object(); $classMetadatumType = $metadatum->get_metadatum_type_object();
if( is_object( $classFieldType ) ){ if( is_object( $classMetadatumType ) ){
if( method_exists ( $classFieldType , 'validate' ) ){ if( method_exists ( $classMetadatumType , 'validate' ) ){
if( ! $classFieldType->validate( $this ) ) { if( ! $classMetadatumType->validate( $this ) ) {
$this->add_error('field_type_error', $classFieldType->get_errors() ); $this->add_error('metadatum_type_error', $classMetadatumType->get_errors() );
return false; return false;
} }
} }
@ -344,25 +344,25 @@ class Item_Metadata_Entity extends Entity {
} }
if ($this->is_required() && !$one_filled) { 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; return false;
} }
if (!$valid) { if (!$valid) {
$this->add_error('invalid', $field->get_name() . ' is invalid'); $this->add_error('invalid', $metadatum->get_name() . ' is invalid');
return false; return false;
} }
$this->set_as_valid(); $this->set_as_valid();
return true; return true;
} else { } else {
$this->add_error('invalid', $field->get_name() . ' is invalid'); $this->add_error('invalid', $metadatum->get_name() . ' is invalid');
return false; return false;
} }
} else { } else {
if( is_array($value) ){ 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; return false;
} }
@ -372,7 +372,7 @@ class Item_Metadata_Entity extends Entity {
$test = $Tainacan_Items->fetch([ $test = $Tainacan_Items->fetch([
'meta_query' => [ 'meta_query' => [
[ [
'key' => $this->field->get_id(), 'key' => $this->metadatum->get_id(),
'value' => $value 'value' => $value
], ],
], ],
@ -380,7 +380,7 @@ class Item_Metadata_Entity extends Entity {
], $item->get_collection()); ], $item->get_collection());
if ($test->have_posts()) { 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; return false;
} }
} }

View File

@ -336,13 +336,13 @@ class Item extends Entity {
/** /**
* Return a List of ItemMetadata objects * 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 * @return array Array of ItemMetadata objects
*/ */
function get_fields($args = []) { function get_metadata($args = []) {
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
return $Tainacan_Item_Metadata->fetch( $this, 'OBJECT', $args ); return $Tainacan_Item_Metadata->fetch( $this, 'OBJECT', $args );
@ -380,18 +380,18 @@ class Item extends Entity {
$is_valid = false; $is_valid = false;
} }
$arrayItemMetadata = $this->get_fields(); $arrayItemMetadata = $this->get_metadata();
if ( $arrayItemMetadata ) { if ( $arrayItemMetadata ) {
foreach ( $arrayItemMetadata as $itemMetadata ) { foreach ( $arrayItemMetadata as $itemMetadata ) {
// skip validation for Compound Fields // skip validation for Compound Metadata
if ( $itemMetadata->get_field()->get_field_type() == 'Tainacan\Field_Types\Compound' ) { if ( $itemMetadata->get_metadatum()->get_metadatum_type() == 'Tainacan\Metadatum_Types\Compound' ) {
continue; continue;
} }
if ( ! $itemMetadata->validate() ) { if ( ! $itemMetadata->validate() ) {
$errors = $itemMetadata->get_errors(); $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; $is_valid = false;
} }
} }
@ -410,7 +410,7 @@ class Item extends Entity {
* {@inheritDoc} * {@inheritDoc}
* @see \Tainacan\Entities\Entity::validate() * @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', [ if ( ! in_array( $this->get_status(), apply_filters( 'tainacan-status-require-validation', [
'publish', 'publish',
'future', 'future',
@ -449,15 +449,15 @@ class Item extends Entity {
/** /**
* Return the item metadata as a HTML string to be used as output. * 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 * it returns all metadata
* *
* @param array|string $args { * @param array|string $args {
* Optional. Array or string of arguments. * 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 * @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 $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 * Default: true
* @type string $before_title String to be added before each metadata title * @type string $before_title String to be added before each metadata title
* Default '<h3>' * Default '<h3>'
@ -487,7 +487,7 @@ class Item extends Entity {
public function get_metadata_as_html($args = array()) { public function get_metadata_as_html($args = array()) {
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance(); $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
$return = ''; $return = '';
@ -508,33 +508,33 @@ class Item extends Entity {
if (!is_null($args['metadata'])) { if (!is_null($args['metadata'])) {
$field_object = null; $metadatum_object = null;
if ( $field instanceof \Tainacan\Entities\Field ) { if ( $metadatum instanceof \Tainacan\Entities\Metadatum ) {
$field_object = $field; $metadatum_object = $metadatum;
} elseif ( is_int($field) ) { } elseif ( is_int($metadatum) ) {
$field_object = $Tainacan_Fields->fetch($field); $metadatum_object = $Tainacan_Metadata->fetch($metadatum);
} elseif ( is_string($field) ) { } elseif ( is_string($metadatum) ) {
$query = $Tainacan_Fields->fetch(['slug' => $field], 'OBJECT'); $query = $Tainacan_Metadata->fetch(['slug' => $metadatum], 'OBJECT');
if ( is_array($query) && sizeof($query) == 1 && isset($field[0])) { if ( is_array($query) && sizeof($query) == 1 && isset($metadatum[0])) {
$field_object = $field[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']) if ( is_array($args['metadata__not_in'])
&& ( && (
in_array($field_object->get_slug(), $args['metadata__not_in']) || in_array($metadatum_object->get_slug(), $args['metadata__not_in']) ||
in_array($field_object->get_id(), $args['metadata__not_in']) in_array($metadatum_object->get_id(), $args['metadata__not_in'])
) )
) { ) {
return $return; 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']) { 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']; $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 ( $fto->get_core() ) {
if ( $args['exclude_core'] ) { if ( $args['exclude_core'] ) {
@ -595,7 +595,7 @@ class Item extends Entity {
} }
if ($item_meta->has_value() || !$args['hide_empty']) { 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']; $return .= $args['before_value'] . $item_meta->get_value_as_html() . $args['after_value'];
} }
} }

View File

@ -5,9 +5,9 @@ namespace Tainacan\Entities;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); 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 protected
$name, $name,
$slug, $slug,
@ -21,21 +21,31 @@ class Field extends Entity {
$collection_key, $collection_key,
$mask, $mask,
$default_value, $default_value,
$field_type, $metadatum_type,
$field_type_options; $metadatum_type_options;
// Collection getter and setter declared here // Collection getter and setter declared here
use \Tainacan\Traits\Entity_Collection_Relation; use \Tainacan\Traits\Entity_Collection_Relation;
public $enabled_for_collection = true; 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} * {@inheritDoc}
* @see \Tainacan\Entities\Entity::repository * @see \Tainacan\Entities\Entity::repository
* @var string * @var string
*/ */
protected $repository = 'Fields'; protected $repository = 'Metadata';
public function __toString(){ public function __toString(){
return 'Hello, my name is '. $this->get_name(); 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 * @return string
*/ */
@ -66,7 +76,7 @@ class Field extends Entity {
} }
/** /**
* Get field slug * Get metadatum slug
* *
* @return string * @return string
*/ */
@ -75,7 +85,7 @@ class Field extends Entity {
} }
/** /**
* Return the field order type * Return the metadatum order type
* *
* @return string * @return string
*/ */
@ -93,7 +103,7 @@ class Field extends Entity {
} }
/** /**
* Return the field description * Return the metadatum description
* *
* @return string * @return string
*/ */
@ -102,7 +112,7 @@ class Field extends Entity {
} }
/** /**
* Return if is a required field * Return if is a required metadatum
* *
* @return boolean * @return boolean
*/ */
@ -111,7 +121,7 @@ class Field extends Entity {
} }
/** /**
* Return if is a multiple field * Return if is a multiple metadatum
* *
* @return boolean * @return boolean
*/ */
@ -129,7 +139,7 @@ class Field extends Entity {
} }
/** /**
* Return if field is key * Return if metadatum is key
* *
* @return boolean * @return boolean
*/ */
@ -147,7 +157,7 @@ class Field extends Entity {
} }
/** /**
* Return the field default value * Return the metadatum default value
* *
* @return string || integer * @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(){ function get_metadatum_type_object(){
$class_name = $this->get_field_type(); $class_name = $this->get_metadatum_type();
$object_type = new $class_name(); $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 $object_type;
} }
/** /**
* Return the class name for the field type * Return the class name for the metadatum type
* *
* @return string The * @return string The
*/ */
function get_field_type(){ function get_metadatum_type(){
return $this->get_mapped_property('field_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(){ function get_metadatum_type_options(){
return $this->get_mapped_property('field_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 * @return bool
*/ */
function get_accept_suggestion() { function get_accept_suggestion() {
@ -202,7 +212,7 @@ class Field extends Entity {
} }
/** /**
* Set the field name * Set the metadatum name
* *
* @param [string] $value * @param [string] $value
* @return void * @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. * 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 * 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 * @param [string] $value
* @return void * @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 * @param [integer] $value The ID from parent
* @return void * @return void
@ -248,7 +258,7 @@ class Field extends Entity {
} }
/** /**
* Set field description * Set metadatum description
* *
* @param [string] $value The text description * @param [string] $value The text description
* @return void * @return void
@ -258,7 +268,7 @@ class Field extends Entity {
} }
/** /**
* Allow the field be required * Allow the metadatum be required
* *
* @param [boolean] $value * @param [boolean] $value
* @return void * @return void
@ -268,7 +278,7 @@ class Field extends Entity {
} }
/** /**
* Allow multiple fields * Allow multiple metadata
* *
* @param [boolean] $value * @param [boolean] $value
* @return void * @return void
@ -278,7 +288,7 @@ class Field extends Entity {
} }
/** /**
* The number of possible fields * The number of possible metadata
* *
* @param [string] $value * @param [string] $value
* @return void * @return void
@ -298,7 +308,7 @@ class Field extends Entity {
} }
/** /**
* Set mask for the field * Set mask for the metadatum
* *
* @param [string] $value * @param [string] $value
* @return void * @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 ){ public function set_metadatum_type( $value ){
$this->set_mapped_property('field_type', ( is_object( $value ) ) ? get_class( $value ) : $value ) ; // Encode to avoid backslaches removal $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 * @param bool $value
*/ */
function set_accept_suggestion( $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 * @param [string || integer] $value
* @return void * @return void
*/ */
function set_field_type_options( $value ){ function set_metadatum_type_options( $value ){
$this->set_mapped_property('field_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 * @param array $value
*/ */
public function set_exposer_mapping( $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() { public function get_enabled_for_collection() {
@ -399,7 +409,7 @@ class Field extends Entity {
/** /**
* {@inheritdoc } * {@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 * @return bool valid or not
* @throws \Exception * @throws \Exception
@ -411,28 +421,28 @@ class Field extends Entity {
if (false === $is_valid) if (false === $is_valid)
return false; 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->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')); $this->add_error($this->get_id(), __('Compound metadata do not support metadata with multiple values (except categories)', 'tainacan'));
return false; return false;
} }
} }
// You cant have a category field inside a multiple compound field // You cant have a category metadatum inside a multiple compound metadatum
if ( $this->get_parent() > 0 && $this->get_field_type_object()->get_primitive_type() == 'term' ) { if ( $this->get_parent() > 0 && $this->get_metadatum_type_object()->get_primitive_type() == 'term' ) {
$parent_field = new \Tainacan\Entities\Field($this->get_parent()); $parent_metadatum = new \Tainacan\Entities\Metadatum($this->get_parent());
if ( $parent_field->is_multiple() ) { if ( $parent_metadatum->is_multiple() ) {
$this->add_error($this->get_id(), __('Taxonomy metadata can not be used inside Compound metadata with multiple values', 'tainacan')); $this->add_error($this->get_id(), __('Taxonomy metadata can not be used inside Compound metadata with multiple values', 'tainacan'));
return false; return false;
} }
} }
if ( $this->get_field_type() == 'Tainacan\Field_Types\Compound' && $this->is_multiple() ) { if ( $this->get_metadatum_type() == 'Tainacan\Metadatum_Types\Compound' && $this->is_multiple() ) {
$Tainacan_fields = \Tainacan\Repositories\Fields::get_instance(); $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
$children = $Tainacan_fields->fetch( $children = $Tainacan_Metadata->fetch(
[ [
'parent' => $this->get_id(), 'parent' => $this->get_id(),
'field_type' => 'Tainacan\Field_Types\Category', 'metadatum_type' => 'Tainacan\Metadatum_Types\Category',
'post_status' => 'any' 'post_status' => 'any'
] ]
, 'OBJECT'); , '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)) { if (is_object($fto)) {
$is_valid = $fto->validate_options($this); $is_valid = $fto->validate_options($this);
@ -456,10 +466,10 @@ class Field extends Entity {
} }
if (!is_array($is_valid)) { 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; return false;

View File

@ -48,21 +48,21 @@
export default { export default {
created(){ created(){
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id; 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; const vm = this;
let in_route = '/collection/' + this.collection + '/fields/' + this.field; let in_route = '/collection/' + this.collection + '/metadata/' + this.metadatum;
if(this.isRepositoryLevel){ if(this.isRepositoryLevel || this.collection == 'filter_in_repository'){
in_route = '/fields/'+ this.field; in_route = '/metadata/'+ this.metadatum;
} }
axios.get(in_route) axios.get(in_route)
.then( res => { .then( res => {
let result = res.data; let result = res.data;
if( result && result.field_type ){ if( result && result.metadatum_type ){
vm.field_object = result; vm.metadatum_object = result;
vm.type = result.field_type; vm.type = result.metadatum_type;
vm.selectedValues(); vm.selectedValues();
} }
}) })
@ -78,7 +78,7 @@
isLoading: false, isLoading: false,
type: '', type: '',
collection: '', collection: '',
field: '', metadatum: '',
label: '' label: ''
} }
}, },
@ -97,7 +97,7 @@
onSelect(){ onSelect(){
this.$emit('input', { this.$emit('input', {
filter: 'autocomplete', filter: 'autocomplete',
field_id: this.field, metadatum_id: this.metadatum,
collection_id: this.collection, collection_id: this.collection,
value: this.results value: this.results
}); });
@ -105,13 +105,13 @@
search( query ){ search( query ){
let promise = null; let promise = null;
this.options = []; this.options = [];
if ( this.type === 'Tainacan\\Field_Types\\Relationship' ) { if ( this.type === 'Tainacan\\Metadatum_Types\\Relationship' ) {
let collectionTarget = ( this.field_object && this.field_object.field_type_options.collection_id ) ? let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadatum_type_options.collection_id ) ?
this.field_object.field_type_options.collection_id : this.collection_id; this.metadatum_object.metadatum_type_options.collection_id : this.collection_id;
promise = this.getValuesRelationship( collectionTarget ); promise = this.getValuesRelationship( collectionTarget );
} else { } else {
promise = this.getValuesPlainText( this.field, query, this.isRepositoryLevel ); promise = this.getValuesPlainText( this.metadatum, query, this.isRepositoryLevel );
} }
promise.then( () => { promise.then( () => {
@ -126,14 +126,14 @@
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) ) if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false; 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){ if ( index >= 0){
let metadata = this.query.metaquery[ index ]; let metadata = this.query.metaquery[ index ];
let collectionTarget = ( this.field_object && this.field_object.field_type_options.collection_id ) ? let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadatum_type_options.collection_id ) ?
this.field_object.field_type_options.collection_id : this.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 }); let query = qs.stringify({ postin: metadata.value });
axios.get('/collection/' + collectionTarget + '/items?' + query) axios.get('/collection/' + collectionTarget + '/items?' + query)
@ -161,7 +161,7 @@
this.selected = ''; this.selected = '';
this.$emit('input', { this.$emit('input', {
filter: 'autocomplete', filter: 'autocomplete',
field_id: this.field, metadatum_id: this.metadatum,
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id, collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
value: '' value: ''
}); });

View File

@ -4,7 +4,7 @@ namespace Tainacan\Filter_Types;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/** /**
* Class TainacanFieldType * Class TainacanMetadatumType
*/ */
class Autocomplete extends Filter_Type { class Autocomplete extends Filter_Type {
@ -21,7 +21,7 @@ class Autocomplete extends Filter_Type {
public function render( $filter ){ public function render( $filter ){
return '<tainacan-filter-autocomplete name="'.$filter->get_name().'" return '<tainacan-filter-autocomplete name="'.$filter->get_name().'"
collection_id="'.$filter->get_collection_id().'" collection_id="'.$filter->get_collection_id().'"
filter_type="'.$filter->get_field()->get_field_type().'" filter_type="'.$filter->get_metadatum()->get_metadatum_type().'"
field_id="'.$filter->get_field()->get_id().'"></tainacan-filter-autocomplete>'; metadatum_id="'.$filter->get_metadatum()->get_id().'"></tainacan-filter-autocomplete>';
} }
} }

View File

@ -20,8 +20,8 @@
export default { export default {
created(){ created(){
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id; 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 ;
this.type = ( this.filter_type ) ? this.filter_type : this.filter.field.field_type; this.type = ( this.filter_type ) ? this.filter_type : this.filter.metadatum.metadatum_type;
this.loadOptions(); this.loadOptions();
}, },
data(){ data(){
@ -30,21 +30,21 @@
options: [], options: [],
type: '', type: '',
collection: '', collection: '',
field: '', metadatum: '',
selected: [], selected: [],
taxonomy: '' taxonomy: ''
} }
}, },
props: { props: {
filter: { 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 metadatum_id: [Number], // not required, but overrides the filter metadatum id if is set
collection_id: [Number], // not required, but overrides the filter field 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 field type if is set filter_type: [String], // not required, but overrides the filter metadatum type if is set
id: '', id: '',
query: { query: {
type: Object // concentrate all attributes field id and type type: Object // concentrate all attributes metadatum id and type
} }
}, },
watch: { watch: {
@ -69,10 +69,10 @@
let promise = null; let promise = null;
this.isLoading = true; this.isLoading = true;
axios.get('/collection/'+ this.collection +'/fields/' + this.field) axios.get('/collection/'+ this.collection +'/metadata/' + this.metadatum)
.then( res => { .then( res => {
let field = res.data; let metadatum = res.data;
promise = this.getValuesCategory( field.field_type_options.taxonomy_id ); promise = this.getValuesCategory( metadatum.metadatum_type_options.taxonomy_id );
promise.then( () => { promise.then( () => {
this.isLoading = false; this.isLoading = false;
@ -106,7 +106,7 @@
if ( !this.query || !this.query.taxquery || !Array.isArray( this.query.taxquery ) ) if ( !this.query || !this.query.taxquery || !Array.isArray( this.query.taxquery ) )
return false; 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){ if ( index >= 0){
let metadata = this.query.taxquery[ index ]; let metadata = this.query.taxquery[ index ];
this.selected = metadata.terms; this.selected = metadata.terms;
@ -119,7 +119,7 @@
filter: 'selectbox', filter: 'selectbox',
taxonomy: this.taxonomy, taxonomy: this.taxonomy,
compare: 'IN', compare: 'IN',
field_id: this.field, metadatum_id: this.metadatum,
collection_id: this.collection, collection_id: this.collection,
terms: this.selected terms: this.selected
}); });

View File

@ -23,8 +23,8 @@
export default { export default {
created(){ created(){
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id; 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 ;
this.type = ( this.filter_type ) ? this.filter_type : this.filter.field.field_type; this.type = ( this.filter_type ) ? this.filter_type : this.filter.metadatum.metadatum_type;
this.loadOptions(); this.loadOptions();
}, },
data(){ data(){
@ -32,21 +32,21 @@
isLoading: false, isLoading: false,
options: [], options: [],
collection: '', collection: '',
field: '', metadatum: '',
selected: '', selected: '',
taxonomy: '' taxonomy: ''
} }
}, },
props: { props: {
filter: { 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 metadatum_id: [Number], // not required, but overrides the filter metadatum id if is set
collection_id: [Number], // not required, but overrides the filter field 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 field type if is set filter_type: [String], // not required, but overrides the filter metadatum type if is set
id: '', id: '',
query: { query: {
type: Object // concentrate all attributes field id and type type: Object // concentrate all attributes metadatum id and type
} }
}, },
watch: { watch: {
@ -71,10 +71,10 @@
let promise = null; let promise = null;
this.isLoading = true; this.isLoading = true;
axios.get('/collection/'+ this.collection +'/fields/' + this.field) axios.get('/collection/'+ this.collection +'/metadata/' + this.metadatum)
.then( res => { .then( res => {
let field = res.data; let metadatum = res.data;
promise = this.getValuesCategory( field.field_type_options.taxonomy_id ); promise = this.getValuesCategory( metadatum.metadatum_type_options.taxonomy_id );
promise.then( () => { promise.then( () => {
this.isLoading = false; this.isLoading = false;
@ -108,7 +108,7 @@
if ( !this.query || !this.query.taxquery || !Array.isArray( this.query.taxquery ) ) if ( !this.query || !this.query.taxquery || !Array.isArray( this.query.taxquery ) )
return false; 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){ if ( index >= 0){
let metadata = this.query.taxquery[ index ]; let metadata = this.query.taxquery[ index ];
this.selected = metadata.terms; this.selected = metadata.terms;
@ -121,7 +121,7 @@
filter: 'selectbox', filter: 'selectbox',
compare: 'IN', compare: 'IN',
taxonomy: this.taxonomy, taxonomy: this.taxonomy,
field_id: this.field, metadatum_id: this.metadatum,
collection_id: this.collection, collection_id: this.collection,
terms: this.selected terms: this.selected
}); });

View File

@ -19,19 +19,19 @@
export default { export default {
created(){ created(){
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id; 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 ;
this.type = ( this.filter_type ) ? this.filter_type : this.filter.field.field_type; 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){ if(this.isRepositoryLevel || this.collection == 'filter_in_repository'){
in_route = '/fields/' + this.field; in_route = '/metadata/'+ this.metadatum;
} }
axios.get(in_route) axios.get(in_route)
.then( res => { .then( res => {
let field = res.data; let metadatum = res.data;
this.selectedValues( field.field_type_options.taxonomy_id ); this.selectedValues( metadatum.metadatum_type_options.taxonomy_id );
}); });
}, },
data(){ data(){
@ -42,20 +42,20 @@
isLoading: false, isLoading: false,
type: '', type: '',
collection: '', collection: '',
field: '', metadatum: '',
taxonomy: '' taxonomy: ''
} }
}, },
props: { props: {
filter: { 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 metadatum_id: [Number], // not required, but overrides the filter metadatum id if is set
collection_id: [Number], // not required, but overrides the filter field 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 field type if is set filter_type: [String], // not required, but overrides the filter metadatum type if is set
id: '', id: '',
query: { query: {
type: Object // concentrate all attributes field id and type type: Object // concentrate all attributes metadatum id and type
}, },
isRepositoryLevel: Boolean, isRepositoryLevel: Boolean,
}, },
@ -72,7 +72,7 @@
filter: 'taginput', filter: 'taginput',
compare: 'IN', compare: 'IN',
taxonomy: this.taxonomy, 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, collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
terms: values terms: values
}); });
@ -83,12 +83,12 @@
let promise = null; let promise = null;
this.options = []; this.options = [];
const q = query; 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) axios.get(endpoint)
.then( res => { .then( res => {
let field = res.data; let metadatum = res.data;
promise = this.getValuesCategory( field.field_type_options.taxonomy_id, q ); promise = this.getValuesCategory( metadatum.metadatum_type_options.taxonomy_id, q );
this.isLoading = true; this.isLoading = true;
promise.then( () => { promise.then( () => {
this.isLoading = false; this.isLoading = false;
@ -119,7 +119,7 @@
if ( !this.query || !this.query.taxquery || !Array.isArray( this.query.taxquery ) ) if ( !this.query || !this.query.taxquery || !Array.isArray( this.query.taxquery ) )
return false; 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){ if ( index >= 0){
let metadata = this.query.taxquery[ index ]; let metadata = this.query.taxquery[ index ];
for ( let id of metadata.terms ){ for ( let id of metadata.terms ){

View File

@ -4,7 +4,7 @@ namespace Tainacan\Filter_Types;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/** /**
* Class TainacanFieldType * Class TainacanMetadatumType
*/ */
class CategoryCheckbox extends Filter_Type { class CategoryCheckbox extends Filter_Type {
@ -20,8 +20,8 @@ class CategoryCheckbox extends Filter_Type {
public function render( $filter ){ public function render( $filter ){
return '<tainacan-filter-category-checkbox name="'.$filter->get_name().'" 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().'" 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>';
} }
} }

View File

@ -4,7 +4,7 @@ namespace Tainacan\Filter_Types;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/** /**
* Class TainacanFieldType * Class TainacanMetadatumType
*/ */
class CategorySelectbox extends Filter_Type { class CategorySelectbox extends Filter_Type {
@ -20,8 +20,8 @@ class CategorySelectbox extends Filter_Type {
public function render( $filter ){ public function render( $filter ){
return '<tainacan-filter-category-selectbox name="'.$filter->get_name().'" 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().'" 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>';
} }
} }

View File

@ -20,8 +20,8 @@ class CategoryTaginput extends Filter_Type {
public function render( $filter ){ public function render( $filter ){
return '<tainacan-filter-category-taginput name="'.$filter->get_name().'" 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().'" 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>';
} }
} }

View File

@ -3,7 +3,7 @@
<div <div
v-for="(option, index) in options" v-for="(option, index) in options"
:key="index" :key="index"
class="field"> class="metadatum">
<b-checkbox <b-checkbox
v-model="selected" v-model="selected"
:native-value="option.value" :native-value="option.value"
@ -19,21 +19,21 @@
export default { export default {
created(){ created(){
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id; 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; 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){ if(this.isRepositoryLevel || this.collection == 'filter_in_repository'){
in_route = '/fields?nopaging=1'; in_route = '/metadata?nopaging=1';
} }
axios.get(in_route) axios.get(in_route)
.then( res => { .then( res => {
let result = res.data; let result = res.data;
if( result && result.field_type ){ if( result && result.metadatum_type ){
vm.field_object = result; vm.metadatum_object = result;
vm.type = result.field_type; vm.type = result.metadatum_type;
vm.loadOptions(); vm.loadOptions();
} }
}) })
@ -50,9 +50,9 @@
options: [], options: [],
type: '', type: '',
collection: '', collection: '',
field: '', metadatum: '',
selected: [], selected: [],
field_object: {} metadatum_object: {}
} }
}, },
mixins: [filter_type_mixin], mixins: [filter_type_mixin],
@ -67,13 +67,13 @@
let promise = null; let promise = null;
this.isLoading = true; this.isLoading = true;
if ( this.type === 'Tainacan\\Field_Types\\Relationship' ) { if ( this.type === 'Tainacan\\Metadatum_Types\\Relationship' ) {
let collectionTarget = ( this.field_object && this.field_object.field_type_options.collection_id ) ? let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadatum_type_options.collection_id ) ?
this.field_object.field_type_options.collection_id : this.collection_id; this.metadatum_object.metadatum_type_options.collection_id : this.collection_id;
promise = this.getValuesRelationship( collectionTarget ); promise = this.getValuesRelationship( collectionTarget );
} else { } else {
promise = this.getValuesPlainText( this.field, null, this.isRepositoryLevel ); promise = this.getValuesPlainText( this.metadatum, null, this.isRepositoryLevel );
} }
promise.then(() => { promise.then(() => {
@ -89,7 +89,7 @@
this.$emit('input', { this.$emit('input', {
filter: 'checkbox', filter: 'checkbox',
compare: 'IN', compare: 'IN',
field_id: this.field, metadatum_id: this.metadatum,
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id, collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
value: this.selected value: this.selected
}); });
@ -98,7 +98,7 @@
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) ) if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false; 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){ if ( index >= 0){
let metadata = this.query.metaquery[ index ]; let metadata = this.query.metaquery[ index ];
this.selected = metadata.value; this.selected = metadata.value;

View File

@ -4,7 +4,7 @@ namespace Tainacan\Filter_Types;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/** /**
* Class TainacanFieldType * Class TainacanMetadatumType
*/ */
class Checkbox extends Filter_Type { class Checkbox extends Filter_Type {
@ -20,8 +20,8 @@ class Checkbox extends Filter_Type {
public function render( $filter ){ public function render( $filter ){
return '<tainacan-filter-checkbox name="'.$filter->get_name().'" 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().'" 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>';
} }
} }

View File

@ -64,20 +64,20 @@
created(){ created(){
const vm = this; const vm = this;
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id; 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){ if(this.isRepositoryLevel || this.collection == 'filter_in_repository'){
in_route = '/fields/'+ this.field; in_route = '/metadata/'+ this.metadatum;
} }
axios.get(in_route) axios.get(in_route)
.then( res => { .then( res => {
let result = res.data; let result = res.data;
if( result && result.field_type ){ if( result && result.metadatum_type ){
vm.field_object = result; vm.metadatum_object = result;
vm.type = ( result.field_type === 'Tainacan\\Field_Types\\Date') ? 'date' : 'numeric'; vm.type = ( result.metadatum_type === 'Tainacan\\Metadatum_Types\\Date') ? 'date' : 'numeric';
vm.selectedValues(); vm.selectedValues();
} }
}) })
@ -96,16 +96,16 @@
clear: false, clear: false,
type: 'numeric', type: 'numeric',
collection: '', collection: '',
field: '', metadatum: '',
field_object: {}, metadatum_object: {},
} }
}, },
props: { props: {
filter: { 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 metadatum_id: [Number], // not required, but overrides the filter metadatum id if is set
collection_id: [Number], // not required, but overrides the filter field id if is set collection_id: [Number], // not required, but overrides the filter metadatum id if is set
id: '', id: '',
query: Object, query: Object,
isRepositoryLevel: Boolean, isRepositoryLevel: Boolean,
@ -165,7 +165,7 @@
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) ) if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false; 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){ if ( index >= 0){
let metadata = this.query.metaquery[ index ]; let metadata = this.query.metaquery[ index ];
if( metadata.value.length > 0 && this.type === 'numeric'){ if( metadata.value.length > 0 && this.type === 'numeric'){
@ -204,7 +204,7 @@
this.$emit('input', { this.$emit('input', {
filter: 'range', filter: 'range',
compare: 'BETWEEN', compare: 'BETWEEN',
field_id: this.field, metadatum_id: this.metadatum,
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id, collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
value: '' value: ''
}); });
@ -278,7 +278,7 @@
filter: 'range', filter: 'range',
type: type, type: type,
compare: 'BETWEEN', compare: 'BETWEEN',
field_id: vm.field, metadatum_id: vm.metadatum,
collection_id: ( vm.collection_id ) ? vm.collection_id : vm.filter.collection_id, collection_id: ( vm.collection_id ) ? vm.collection_id : vm.filter.collection_id,
value: values value: values
}); });

View File

@ -5,7 +5,7 @@ namespace Tainacan\Filter_Types;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/** /**
* Class TainacanFieldType * Class TainacanMetadatumType
*/ */
class Custom_Interval extends Filter_Type { class Custom_Interval extends Filter_Type {
@ -17,14 +17,14 @@ class Custom_Interval extends Filter_Type {
/** /**
* @param $filter * @param $filter
* @return string * @return string
* @internal param $field * @internal param $metadatum
*/ */
public function render( $filter ){ 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 return '<tainacan-filter-custom-interval
name="'.$filter->get_name().'" name="'.$filter->get_name().'"
typeRange="'.$type.'" typeRange="'.$type.'"
collection_id="'.$filter->get_collection_id().'" 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>';
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
namespace Tainacan\Filter_Types; namespace Tainacan\Filter_Types;
use Tainacan\Field_Types; use Tainacan\Metadatum_Types;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); 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')); 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(){ public function form(){
@ -72,19 +72,19 @@ abstract class Filter_Type {
* *
* This method should be declared by each filter type sub classes * 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 * @throws \Exception
*/ */
public function validate_options(\Tainacan\Entities\Filter $filter) { public function validate_options(\Tainacan\Entities\Filter $filter) {
$field_type = $filter->get_field()->get_field_type(); $metadatum_type = $filter->get_metadatum()->get_metadatum_type();
//if there is no field to validate //if there is no metadatum to validate
if( !$field_type ){ if( !$metadatum_type ){
return true; 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 )){ if(in_array( $class->get_primitive_type(), $this->supported_types )){
return true; return true;

View File

@ -3,21 +3,21 @@ import { tainacan as axios } from '../../js/axios/axios';
export const filter_type_mixin = { export const filter_type_mixin = {
props: { props: {
filter: { 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 metadatum_id: [Number], // not required, but overrides the filter metadatum id if is set
collection_id: [Number], // not required, but overrides the filter field 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 field type if is set filter_type: [String], // not required, but overrides the filter metadatum type if is set
id: '', id: '',
query: {} query: {}
}, },
methods: { 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){ if(isRepositoryLevel){
url = '/fields/' + fieldId + '?fetch=all_field_values&nopaging=1'; url = '/metadata/' + metadatumId + '?fetch=all_metadatum_values&nopaging=1';
} }
if( search ){ if( search ){

View File

@ -25,21 +25,21 @@
export default { export default {
created(){ created(){
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id; 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; const vm = this;
let in_route = '/collection/' + this.collection + '/fields/' + this.field; let in_route = '/collection/' + this.collection + '/metadata/' + this.metadatum;
if(this.isRepositoryLevel){ if(this.isRepositoryLevel || this.collection == 'filter_in_repository'){
in_route = '/fields/'+ this.field; in_route = '/metadata/'+ this.metadatum;
} }
axios.get(in_route) axios.get(in_route)
.then( res => { .then( res => {
let result = res.data; let result = res.data;
if( result && result.field_type ){ if( result && result.metadatum_type ){
vm.field_object = result; vm.metadatum_object = result;
vm.type = result.field_type; vm.type = result.metadatum_type;
vm.loadOptions(); vm.loadOptions();
} }
}) })
@ -56,7 +56,7 @@
options: [], options: [],
type: '', type: '',
collection: '', collection: '',
field: '' metadatum: ''
} }
}, },
mixins: [filter_type_mixin], mixins: [filter_type_mixin],
@ -64,7 +64,7 @@
selected() { selected() {
if ( this.query && this.query.metaquery && Array.isArray( this.query.metaquery ) ) { 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){ if ( index >= 0){
let metadata = this.query.metaquery[ index ]; let metadata = this.query.metaquery[ index ];
return metadata.value; return metadata.value;
@ -78,7 +78,7 @@
this.isLoading = true; this.isLoading = true;
let promise = null; let promise = null;
promise = this.getValuesPlainText( this.field, null, this.isRepositoryLevel ); promise = this.getValuesPlainText( this.metadatum, null, this.isRepositoryLevel );
promise.then(() => { promise.then(() => {
this.isLoading = false; this.isLoading = false;
@ -91,7 +91,7 @@
onSelect(value){ onSelect(value){
this.$emit('input', { this.$emit('input', {
filter: 'selectbox', filter: 'selectbox',
field_id: this.field, metadatum_id: this.metadatum,
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id, collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
value: ( value ) ? value : '' value: ( value ) ? value : ''
}); });
@ -100,7 +100,7 @@
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) ) if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false; 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){ if ( index >= 0){
let metadata = this.query.metaquery[ index ]; let metadata = this.query.metaquery[ index ];
this.selected = metadata.value; this.selected = metadata.value;

View File

@ -4,7 +4,7 @@ namespace Tainacan\Filter_Types;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/** /**
* Class TainacanFieldType * Class TainacanMetadatumType
*/ */
class Selectbox extends Filter_Type { class Selectbox extends Filter_Type {
@ -20,8 +20,8 @@ class Selectbox extends Filter_Type {
public function render( $filter ){ public function render( $filter ){
return '<tainacan-filter-selectbox name="'.$filter->get_name().'" 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().'" 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>';
} }
} }

View File

@ -21,21 +21,21 @@
export default { export default {
created(){ created(){
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id; 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; const vm = this;
let in_route = '/collection/' + this.collection + '/fields/' + this.field; let in_route = '/collection/' + this.collection + '/metadata/' + this.metadatum;
if(this.isRepositoryLevel){ if(this.isRepositoryLevel || this.collection == 'filter_in_repository'){
in_route = '/fields?nopaging=1'; in_route = '/metadata?nopaging=1';
} }
axios.get(in_route) axios.get(in_route)
.then( res => { .then( res => {
let result = res.data; let result = res.data;
if( result && result.field_type ){ if( result && result.metadatum_type ){
vm.field_object = result; vm.metadatum_object = result;
vm.type = result.field_type; vm.type = result.metadatum_type;
vm.selectedValues(); vm.selectedValues();
} }
}) })
@ -51,8 +51,8 @@
isLoading: false, isLoading: false,
type: '', type: '',
collection: '', collection: '',
field: '', metadatum: '',
field_object: {} metadatum_object: {}
} }
}, },
props: { props: {
@ -71,7 +71,7 @@
this.$emit('input', { this.$emit('input', {
filter: 'taginput', filter: 'taginput',
compare: 'IN', compare: 'IN',
field_id: this.field, metadatum_id: this.metadatum,
collection_id: this.collection, collection_id: this.collection,
value: values value: values
}); });
@ -81,13 +81,13 @@
search( query ){ search( query ){
let promise = null; let promise = null;
this.options = []; this.options = [];
if ( this.type === 'Tainacan\\Field_Types\\Relationship' ) { if ( this.type === 'Tainacan\\Metadatum_Types\\Relationship' ) {
let collectionTarget = ( this.field_object && this.field_object.field_type_options.collection_id ) ? let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadatum_type_options.collection_id ) ?
this.field_object.field_type_options.collection_id : this.collection_id; this.metadatum_object.metadatum_type_options.collection_id : this.collection_id;
promise = this.getValuesRelationship( collectionTarget, query ); promise = this.getValuesRelationship( collectionTarget, query );
} else { } else {
promise = this.getValuesPlainText( this.field, query, this.isRepositoryLevel ); promise = this.getValuesPlainText( this.metadatum, query, this.isRepositoryLevel );
} }
this.isLoading = true; this.isLoading = true;
promise.then(() => { promise.then(() => {
@ -102,14 +102,14 @@
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) ) if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false; 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){ if ( index >= 0){
let metadata = this.query.metaquery[ index ]; let metadata = this.query.metaquery[ index ];
let collectionTarget = ( this.field_object && this.field_object.field_type_options.collection_id ) ? let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadatum_type_options.collection_id ) ?
this.field_object.field_type_options.collection_id : this.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 }); let query = qs.stringify({ postin: metadata.value });
axios.get('/collection/' + collectionTarget + '/items?' + query) axios.get('/collection/' + collectionTarget + '/items?' + query)

View File

@ -4,7 +4,7 @@ namespace Tainacan\Filter_Types;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/** /**
* Class TainacanFieldType * Class TainacanMetadatumType
*/ */
class Taginput extends Filter_Type { class Taginput extends Filter_Type {
@ -20,8 +20,8 @@ class Taginput extends Filter_Type {
public function render( $filter ){ public function render( $filter ){
return '<tainacan-filter-taginput name="'.$filter->get_name().'" 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().'" 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>';
} }
} }

View File

@ -66,7 +66,7 @@
'setPage' 'setPage'
]), ]),
listen( event ){ 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 ){ setFilterTypeMessage( message ){
this.filterTypeMessage = message; this.filterTypeMessage = message;

View File

@ -54,13 +54,13 @@
name: '', name: '',
parent: 0, parent: 0,
showForm: false, showForm: false,
field_id: this.field.field.id metadatum_id: this.metadatum.metadatum.id
} }
}, },
props: { props: {
id: String, id: String,
item_id: [Number,String], item_id: [Number,String],
field: [Number,String], metadatum: [Number,String],
taxonomy_id: [Number,String], taxonomy_id: [Number,String],
value:[ Array, Boolean, Number ], value:[ Array, Boolean, Number ],
options: { options: {
@ -100,8 +100,8 @@
let id = ( res.id ) ? res.id : res.data.id; let id = ( res.id ) ? res.id : res.data.id;
let val = this.value; let val = this.value;
if( !Array.isArray( val ) && this.field.field.multiple === 'no' ){ if( !Array.isArray( val ) && this.metadatum.metadatum.multiple === 'no' ){
axios.patch(`/item/${this.item_id}/metadata/${this.field_id}`, { axios.patch(`/item/${this.item_id}/metadata/${this.metadatum_id}`, {
values: id, values: id,
}).then(() => { }).then(() => {
instance.$emit('newTerm', id); instance.$emit('newTerm', id);
@ -109,7 +109,7 @@
} else { } else {
val = ( val ) ? val : []; val = ( val ) ? val : [];
val.push( id ); 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, values: val,
}).then( () => { }).then( () => {
instance.$emit('newTerm', val); instance.$emit('newTerm', val);

View File

@ -10,8 +10,8 @@
class="add-new-term" class="add-new-term"
v-if="getComponent() !== 'tainacan-category-tag-input' && allowNew" v-if="getComponent() !== 'tainacan-category-tag-input' && allowNew"
:taxonomy_id="taxonomy" :taxonomy_id="taxonomy"
:field="field" :metadatum="metadatum"
:item_id="field.item.id" :item_id="metadatum.item.id"
:value="valueComponent" :value="valueComponent"
:options="getOptions(0)" :options="getOptions(0)"
@newTerm="reload"/> @newTerm="reload"/>
@ -27,15 +27,15 @@
export default { export default {
created(){ created(){
let field_type_options = this.field.field.field_type_options; let metadatum_type_options = this.metadatum.metadatum.metadatum_type_options;
this.component = ( field_type_options && field_type_options.input_type ) this.component = ( metadatum_type_options && metadatum_type_options.input_type )
? this.field.field.field_type_options.input_type : this.componentAttribute ? this.metadatum.metadatum.metadatum_type_options.input_type : this.componentAttribute
this.collectionId = this.field.field.collection_id; this.collectionId = this.metadatum.metadatum.collection_id;
this.taxonomy = field_type_options.taxonomy_id; this.taxonomy = metadatum_type_options.taxonomy_id;
if( field_type_options && field_type_options.allow_new_terms ){ if( metadatum_type_options && metadatum_type_options.allow_new_terms ){
this.allowNew = field_type_options.allow_new_terms === 'yes' this.allowNew = metadatum_type_options.allow_new_terms === 'yes'
} }
this.getTermsFromTaxonomy(); this.getTermsFromTaxonomy();
this.getTermsId(); this.getTermsId();
@ -65,7 +65,7 @@
} }
}, },
props: { props: {
field: { metadatum: {
type: Object type: Object
}, },
componentAttribute: { componentAttribute: {
@ -76,9 +76,9 @@
}, },
methods: { methods: {
getComponent(){ getComponent(){
if( this.field.field if( this.metadatum.metadatum
&& this.field.field.field_type_options && this.field.field.field_type_options.input_type ){ && this.metadatum.metadatum.metadatum_type_options && this.metadatum.metadatum.metadatum_type_options.input_type ){
return this.field.field.field_type_options.input_type; return this.metadatum.metadatum.metadatum_type_options.input_type;
} }
}, },
getTermsFromTaxonomy(){ getTermsFromTaxonomy(){
@ -115,8 +115,8 @@
} }
} }
if( values.length > 0 && this.field.field){ if( values.length > 0 && this.metadatum.metadatum){
this.valueComponent = ( this.field.field && this.field.field.multiple === 'no' ) ? values[0] : values this.valueComponent = ( this.metadatum.metadatum && this.metadatum.metadatum.multiple === 'no' ) ? values[0] : values
} }
}, },

View File

@ -38,8 +38,8 @@
</label> </label>
<b-select <b-select
v-if="listInputType" v-if="listInputType"
name="field_type_options[component_type]" name="metadatum_type_options[component_type]"
placeholder="Select the input type for the category field" placeholder="Select the input type for the category metadatum"
@input="emitValues()" @input="emitValues()"
v-model="input_type"> v-model="input_type">
<option <option
@ -51,8 +51,8 @@
</b-select> </b-select>
<b-select <b-select
name="field_type_options[input_type]" name="metadatum_type_options[input_type]"
placeholder="Select the input type for the category field" placeholder="Select the input type for the category metadatum"
v-model="input_type" v-model="input_type"
@input="emitValues()" @input="emitValues()"
v-else> v-else>
@ -96,7 +96,7 @@
components: {BCheckbox}, components: {BCheckbox},
props: { props: {
value: [ String, Object, Array ], value: [ String, Object, Array ],
field: [ String, Object ], metadatum: [ String, Object ],
errors: [ String, Object, Array ] errors: [ String, Object, Array ]
}, },
created(){ created(){
@ -119,7 +119,7 @@
}, },
computed: { computed: {
listInputType(){ listInputType(){
if( this.field && this.field.multiple === 'no' ){ if( this.metadatum && this.metadatum.multiple === 'no' ){
let types = Object.keys( this.single_types ); let types = Object.keys( this.single_types );
let hasValue = this.value && this.value.input_type && types.indexOf( this.value.input_type ) >= 0; 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' ); this.setInputType( ( hasValue ) ? this.value.input_type : 'tainacan-category-radio' );

View File

@ -1,20 +1,20 @@
<?php <?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\Entities\Item_Metadata_Entity;
use Tainacan\Repositories\Fields; use Tainacan\Repositories\Metadata;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/** /**
* Class TainacanFieldType * Class TainacanMetadatumType
*/ */
class Category extends Field_Type { class Category extends Metadatum_Type {
function __construct(){ function __construct(){
// call field type constructor // call metadatum type constructor
parent::__construct(); parent::__construct();
$this->set_primitive_type('term'); $this->set_primitive_type('term');
@ -55,36 +55,36 @@ class Category extends Field_Type {
$options = ( isset( $this->get_options()['options'] ) ) ? $this->get_options()['options'] : ''; $options = ( isset( $this->get_options()['options'] ) ) ? $this->get_options()['options'] : '';
return '<tainacan-selectbox return '<tainacan-selectbox
options="' . $options . '" options="' . $options . '"
field_id ="'.$itemMetadata->get_field()->get_id().'" metadatum_id ="'.$itemMetadata->get_metadatum()->get_id().'"
item_id="'.$itemMetadata->get_item()->get_id().'" item_id="'.$itemMetadata->get_item()->get_id().'"
value=\''.json_encode( $itemMetadata->get_value() ).'\' 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; return true;
if (empty($this->get_option('taxonomy_id'))) if (empty($this->get_option('taxonomy_id')))
return ['taxonomy_id' => __('Please select a taxonomy', 'tainacan')]; return ['taxonomy_id' => __('Please select a taxonomy', 'tainacan')];
$Tainacan_Fields = Fields::get_instance(); $Tainacan_Metadata = Metadata::get_instance();
$category_fields = $Tainacan_Fields->fetch([ $category_metadata = $Tainacan_Metadata->fetch([
'collection_id' => $field->get_collection_id(), 'collection_id' => $metadatum->get_collection_id(),
'field_type' => 'Tainacan\\Field_Types\\Category' 'metadatum_type' => 'Tainacan\\Metadatum_Types\\Category'
], 'OBJECT'); ], 'OBJECT');
$category_fields = array_map(function ($field_map) { $category_metadata = array_map(function ($metadatum_map) {
$fto = $field_map->get_field_type_object(); $fto = $metadatum_map->get_metadatum_type_object();
return [ $field_map->get_id() => $fto->get_option('taxonomy_id') ]; return [ $metadatum_map->get_id() => $fto->get_option('taxonomy_id') ];
}, $category_fields); }, $category_metadata);
if( is_array( $category_fields ) ){ if( is_array( $category_metadata ) ){
foreach ($category_fields as $field_id => $category_field) { foreach ($category_metadata as $metadatum_id => $category_metadatum) {
if ( is_array( $category_field ) && key($category_field) != $field->get_id() if ( is_array( $category_metadatum ) && key($category_metadatum) != $metadatum->get_id()
&& in_array($this->get_option('taxonomy_id'), $category_field)) { && 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')]; 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 * @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 * @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 * @return string The HTML representation of the value, containing one or multiple terms, separated by comma, linked to term page
*/ */

View File

@ -1,19 +1,19 @@
<?php <?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\Entities\Item_Metadata_Entity;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/** /**
* Class TainacanFieldType * Class TainacanMetadatumType
*/ */
class Compound extends Field_Type { class Compound extends Metadatum_Type {
function __construct(){ function __construct(){
// call field type constructor // call metadatum type constructor
parent::__construct(); parent::__construct();
$this->set_primitive_type('compound'); $this->set_primitive_type('compound');
$this->set_component('tainacan-compound'); $this->set_component('tainacan-compound');
@ -27,14 +27,14 @@ class Compound extends Field_Type {
public function render( $itemMetadata ){ public function render( $itemMetadata ){
return '<tainacan-text return '<tainacan-text
id="tainacan-text-' . $itemMetadata->get_item()->WP_Post->post_name . '" 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().'" item_id="'.$itemMetadata->get_item()->get_id().'"
value=\''.json_encode( $itemMetadata->get_value() ).'\' 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(){ 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 * @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) { 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 ) { foreach ( $value as $compound_element ) {
$return .= '<div class="tainacan-compund-field">'; $return .= '<div class="tainacan-compund-metadatum">';
foreach ( $compound_element as $meta ) { foreach ( $compound_element as $meta ) {
if ( $meta instanceof Item_Metadata_Entity ) { 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"; $return .= '<p>' . $meta->get_value_as_html() . '</p>' . "\n\n";
} }
} }
@ -78,10 +78,10 @@ class Compound extends Field_Type {
foreach ( $value as $meta ) { foreach ( $value as $meta ) {
$return .= '<div class="tainacan-compund-field">'; $return .= '<div class="tainacan-compund-metadatum">';
if ( $meta instanceof Item_Metadata_Entity ) { 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>'; $return .= '<p>' . $meta->get_value_as_html() . '</p>';
} }

View File

@ -1,18 +1,18 @@
<?php <?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!' ); 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(){ function __construct(){
// call field type constructor // call metadatum type constructor
parent::__construct(); parent::__construct();
$this->set_primitive_type('string'); $this->set_primitive_type('string');
$this->set_core(true); $this->set_core(true);
@ -28,21 +28,21 @@ class Core_Description extends Field_Type {
public function render( $itemMetadata ){ public function render( $itemMetadata ){
return '<tainacan-textarea return '<tainacan-textarea
id="tainacan-textarea-' . $itemMetadata->get_item()->WP_Post->post_name . '" 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().'" item_id="'.$itemMetadata->get_item()->get_id().'"
value=\''.json_encode( $itemMetadata->get_value() ).'\' 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(){ 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 * 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; return true;
if ( $field->get_multiple() != 'no') { if ( $metadatum->get_multiple() != 'no') {
return ['multiple' => __('Core Metadata can not accept multiple values', 'tainacan')]; return ['multiple' => __('Core Metadata can not accept multiple values', 'tainacan')];
} }

View File

@ -1,19 +1,19 @@
<?php <?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!' ); 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(){ function __construct(){
// call field type constructor // call metadatum type constructor
parent::__construct(); parent::__construct();
$this->set_primitive_type('string'); $this->set_primitive_type('string');
$this->set_core(true); $this->set_core(true);
@ -29,21 +29,21 @@ class Core_Title extends Field_Type {
public function render( $itemMetadata ){ public function render( $itemMetadata ){
return '<tainacan-text return '<tainacan-text
id="tainacan-text-' . $itemMetadata->get_item()->WP_Post->post_name . '" 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().'" item_id="'.$itemMetadata->get_item()->get_id().'"
value=\''.json_encode( $itemMetadata->get_value() ).'\' 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(){ 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 * 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; return true;
if ( $field->get_multiple() != 'no') { if ( $metadatum->get_multiple() != 'no') {
return ['multiple' => __('Core Metadata can not accept multiple values', 'tainacan')]; return ['multiple' => __('Core Metadata can not accept multiple values', 'tainacan')];
} }

View File

@ -61,7 +61,7 @@
}, },
props: { props: {
id: '', id: '',
field: { metadatum: {
type: Object type: Object
}, },
value: [String, Number, Array], value: [String, Number, Array],

View File

@ -1,17 +1,17 @@
<?php <?php
namespace Tainacan\Field_Types; namespace Tainacan\Metadatum_Types;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
use Tainacan\Helpers; use Tainacan\Helpers;
/** /**
* Class TainacanFieldType * Class TainacanMetadatumType
*/ */
class Date extends Field_Type { class Date extends Metadatum_Type {
function __construct(){ function __construct(){
// call field type constructor // call metadatum type constructor
parent::__construct(); parent::__construct();
$this->set_primitive_type('date'); $this->set_primitive_type('date');
$this->set_component('tainacan-date'); $this->set_component('tainacan-date');
@ -23,9 +23,9 @@ class Date extends Field_Type {
*/ */
public function render( $itemMetadata ){ 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().'" item_id="'.$itemMetadata->get_item()->get_id().'"
value=\''.json_encode( $itemMetadata->get_value() ).'\' value=\''.json_encode( $itemMetadata->get_value() ).'\'
name="'.$itemMetadata->get_field()->get_name().'"></tainacan-date>'; name="'.$itemMetadata->get_metadatum()->get_name().'"></tainacan-date>';
} }
} }

View File

@ -1,36 +1,36 @@
<?php <?php
namespace Tainacan\Field_Types; namespace Tainacan\Metadatum_Types;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); 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 * This is used to relate Metadatum types and filter types, so we know which filter types
* will be available to be used for each field based on its Field Type * 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 * For instance, the Filter Type "input text" may be used to search in any metadatum that has
* a Field Type with a string primitive type. * a Metadatum Type with a string primitive type.
* *
* @var string * @var string
*/ */
private $primitive_type; 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 * @var array
*/ */
private $options = []; private $options = [];
/** /**
* The default values for the field type options array * The default values for the metadatum type options array
* @var array * @var array
*/ */
private $default_options = []; private $default_options = [];
@ -38,9 +38,9 @@ abstract class Field_Type {
private $errors; 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 * * 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 * * 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; 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; 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 * @var string
*/ */
private $component; 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. * that were not set yet.
* @return array Field type options * @return array Metadatum type options
*/ */
public function get_options() { public function get_options() {
return array_merge($this->default_options, $this->options); return array_merge($this->default_options, $this->options);
@ -154,7 +154,7 @@ abstract class Field_Type {
return []; return [];
} }
/** /**
* generate the fields for this field type * generate the metadata for this metadatum type
*/ */
public function form(){ public function form(){
@ -179,12 +179,12 @@ abstract class Field_Type {
/** /**
* Validates the options Array * 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 * @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 field keys and values are error messages. * @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; return true;
} }

View File

@ -24,7 +24,7 @@
}, },
props: { props: {
id: '', id: '',
field: { metadatum: {
type: Object type: Object
}, },
value: [String, Number, Array], value: [String, Number, Array],

View File

@ -1,16 +1,16 @@
<?php <?php
namespace Tainacan\Field_Types; namespace Tainacan\Metadatum_Types;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/** /**
* Class TainacanFieldType * Class TainacanMetadatumType
*/ */
class Numeric extends Field_Type { class Numeric extends Metadatum_Type {
function __construct(){ function __construct(){
// call field type constructor // call metadatum type constructor
parent::__construct(); parent::__construct();
$this->set_primitive_type('float'); $this->set_primitive_type('float');
$this->set_component('tainacan-numeric'); $this->set_component('tainacan-numeric');
@ -23,9 +23,9 @@ class Numeric extends Field_Type {
public function render( $itemMetadata ){ public function render( $itemMetadata ){
return '<tainacan-numeric return '<tainacan-numeric
field_id ="'.$itemMetadata->get_field()->get_id().'" metadatum_id ="'.$itemMetadata->get_metadatum()->get_id().'"
item_id="'.$itemMetadata->get_item()->get_id().'" item_id="'.$itemMetadata->get_item()->get_id().'"
value=\''.json_encode( $itemMetadata->get_value() ).'\' value=\''.json_encode( $itemMetadata->get_value() ).'\'
name="'.$itemMetadata->get_field()->get_name().'"></tainacan-numeric>'; name="'.$itemMetadata->get_metadatum()->get_name().'"></tainacan-numeric>';
} }
} }

View File

@ -12,7 +12,7 @@
:message="$i18n.getHelperMessage('tainacan-relationship', 'collection_id')"/> :message="$i18n.getHelperMessage('tainacan-relationship', 'collection_id')"/>
</label> </label>
<b-select <b-select
name="field_type_relationship[collection_id]" name="metadatum_type_relationship[collection_id]"
placeholder="Select the collection to fetch items" placeholder="Select the collection to fetch items"
v-model="collection" v-model="collection"
@change.native="emitValues()" @change.native="emitValues()"
@ -30,24 +30,24 @@
<transition name="fade"> <transition name="fade">
<div <div
v-if="loadingFields" v-if="loadingMetadata"
class="loading-spinner"/> class="loading-spinner"/>
<b-field <b-field
v-if="hasFields" v-if="hasMetadata"
:addons="false"> :addons="false">
<label class="label"> <label class="label">
{{ $i18n.get('label_fields_for_search') }} {{ $i18n.get('label_metadata_for_search') }}
<help-button <help-button
:title="$i18n.getHelperTitle('tainacan-relationship', 'search')" :title="$i18n.getHelperTitle('tainacan-relationship', 'search')"
:message="$i18n.getHelperMessage('tainacan-relationship', 'search')"/> :message="$i18n.getHelperMessage('tainacan-relationship', 'search')"/>
</label> </label>
<div class="block"> <div class="block">
<div <div
v-for="(option, index) in fields" v-for="(option, index) in metadata"
:key="index" :key="index"
class="field"> class="field">
<b-checkbox <b-checkbox
name="field_type_relationship[search][]" name="metadatum_type_relationship[search][]"
v-model="modelSearch" v-model="modelSearch"
:native-value="option.id"> :native-value="option.id">
{{ option.name }} {{ option.name }}
@ -88,18 +88,18 @@
collection_id: [ Number ], collection_id: [ Number ],
repeated: [ String ], repeated: [ String ],
value: [ String, Object, Array ], value: [ String, Object, Array ],
field: [ String, Object ], metadatum: [ String, Object ],
errors: [ String, Object, Array ] errors: [ String, Object, Array ]
}, },
data(){ data(){
return { return {
icon: '', icon: '',
collections:[], collections:[],
fields: [], metadata: [],
loading: true, loading: true,
collection: '', collection: '',
hasFields: false, hasMetadata: false,
loadingFields: false, loadingMetadata: false,
modelRepeated: 'yes', modelRepeated: 'yes',
modelSearch:[], modelSearch:[],
collectionType: '', collectionType: '',
@ -110,10 +110,10 @@
collection( value ){ collection( value ){
this.collection = value; this.collection = value;
if( value && value !== '' ) { if( value && value !== '' ) {
this.fetchFieldsFromCollection(value); this.fetchMetadataFromCollection(value);
} else { } else {
this.fields = []; this.metadata = [];
this.hasFields = false; this.hasMetadata = false;
this.modelSearch = []; this.modelSearch = [];
this.emitValues(); this.emitValues();
@ -170,32 +170,32 @@
this.$console.log(error); this.$console.log(error);
}); });
}, },
fetchFieldsFromCollection( value ){ fetchMetadataFromCollection( value ){
this.loadingFields = true; this.loadingMetadata = true;
this.hasFields = false; this.hasMetadata = false;
axios.get('/collection/' + value + '/fields/') axios.get('/collection/' + value + '/metadata/')
.then((res) => { .then((res) => {
this.loadingFields = false; this.loadingMetadata = false;
let fields = res.data; let metadata = res.data;
if( fields.length > 0 ){ if( metadata.length > 0 ){
this.fields = []; this.metadata = [];
for( let field of fields ){ for( let metadatum of metadata ){
if( field.field_type !== "Tainacan\\Field_Types\\Relationship"){ if( metadatum.metadatum_type !== "Tainacan\\Metadatum_Types\\Relationship"){
this.fields.push( field ); this.metadata.push( metadatum );
this.hasFields = true; this.hasMetadata = true;
this.checkFields() this.checkMetadata()
} }
} }
} else { } else {
this.fields = []; this.metadata = [];
this.hasFields = false; this.hasMetadata = false;
this.$toast.open({ this.$toast.open({
duration: 4000, duration: 4000,
message: this.$i18n.get('info_warning_no_fields_found'), message: this.$i18n.get('info_warning_no_metadata_found'),
position: 'is-bottom', position: 'is-bottom',
type: 'is-danger' type: 'is-danger'
}) })
@ -204,12 +204,12 @@
this.emitValues(); this.emitValues();
}) })
.catch(() => { .catch(() => {
this.hasFields = false; this.hasMetadata = false;
this.emitValues(); this.emitValues();
}); });
}, },
checkFields(){ checkMetadata(){
if( this.value && this.value.search.length > 0 ){ if( this.value && this.value.search.length > 0 ){
this.modelSearch = this.value.search; this.modelSearch = this.value.search;
} else { } else {

View File

@ -4,7 +4,7 @@
:id="id" :id="id"
v-model="selected" v-model="selected"
:data="options" :data="options"
:maxtags="field.field.multiple === 'yes' ? 100 : 1" :maxtags="metadatum.metadatum.multiple === 'yes' ? 100 : 1"
autocomplete autocomplete
attached attached
:loading="loading" :loading="loading"
@ -21,9 +21,9 @@
export default { export default {
created(){ created(){
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;
if( this.field.value ){ if( this.metadatum.value ){
let query = qs.stringify({ postin: ( Array.isArray( this.field.value ) ) ? this.field.value : [ this.field.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') axios.get('/collection/'+collectionId+'/items?' + query + '?nopaging=1')
.then( res => { .then( res => {
@ -36,13 +36,13 @@
}); });
} }
if( this.field.field.field_type_options if( this.metadatum.metadatum.metadatum_type_options
&& this.field.field.field_type_options.search.length > 0){ && this.metadatum.metadatum.metadatum_type_options.search.length > 0){
axios.get('/collection/'+ collectionId +'/fields?context=edit') axios.get('/collection/'+ collectionId +'/metadata?context=edit')
.then( res => { .then( res => {
for (let item of res.data) { for (let item of res.data) {
if( this.field.field.field_type_options.search.indexOf( item.id ) >= 0 ) if( this.metadatum.metadatum.metadatum_type_options.search.indexOf( item.id ) >= 0 )
this.searchFields.push( item ); this.searchMetadata.push( item );
} }
}) })
.catch(error => { .catch(error => {
@ -58,13 +58,13 @@
loading: false, loading: false,
collectionId: 0, collectionId: 0,
inputValue: null, inputValue: null,
searchFields: [], searchMetadata: [],
queryObject: {}, queryObject: {},
itemsFound: [] itemsFound: []
} }
}, },
props: { props: {
field: { metadatum: {
type: Object type: Object
}, },
collection_id: { collection_id: {
@ -95,7 +95,7 @@
this.$emit('blur'); this.$emit('blur');
}, },
search(query){ search(query){
if( this.selected.length > 0 && this.field.field.multiple === 'no'){ if( this.selected.length > 0 && this.metadatum.metadatum.multiple === 'no'){
return ''; return '';
} }
@ -103,7 +103,7 @@
let metaquery = this.mountQuery( query ); let metaquery = this.mountQuery( query );
this.loading = true; this.loading = true;
this.options = []; 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 )) axios.get('/collection/'+collectionId+'/items?' + qs.stringify( metaquery ))
.then( res => { .then( res => {
this.loading = false; this.loading = false;
@ -122,13 +122,13 @@
}, },
mountQuery( search ){ mountQuery( search ){
let query = [] let query = []
if( this.searchFields.length > 0){ if( this.searchMetadata.length > 0){
query['metaquery'] = []; query['metaquery'] = [];
const metaquery = query['metaquery']; const metaquery = query['metaquery'];
metaquery['relation'] = 'OR' metaquery['relation'] = 'OR'
for( let index in this.searchFields ){ for( let index in this.searchMetadata ){
metaquery[index] = { metaquery[index] = {
key: this.searchFields[index].id, key: this.searchMetadata[index].id,
value: search value: search
} }
} }

View File

@ -1,16 +1,16 @@
<?php <?php
namespace Tainacan\Field_Types; namespace Tainacan\Metadatum_Types;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/** /**
* Class TainacanFieldType * Class TainacanMetadatumType
*/ */
class Relationship extends Field_Type { class Relationship extends Metadatum_Type {
function __construct(){ function __construct(){
// call field type constructor // call metadatum type constructor
parent::__construct(); parent::__construct();
$this->set_primitive_type('item'); $this->set_primitive_type('item');
$this->set_component('tainacan-relationship'); $this->set_component('tainacan-relationship');
@ -45,14 +45,14 @@ class Relationship extends Field_Type {
public function render( $itemMetadata ){ public function render( $itemMetadata ){
return '<tainacan-relationship return '<tainacan-relationship
collection_id="' . $this->get_options()['collection_id'] . '" 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().'" item_id="'.$itemMetadata->get_item()->get_id().'"
value=\''.json_encode( $itemMetadata->get_value() ).'\' 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) { public function validate_options(\Tainacan\Entities\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; return true;
if (!empty($this->get_option('collection_id')) && !is_numeric($this->get_option('collection_id'))) { 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 * @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 * @return string The HTML representation of the value, containing one or multiple items names, linked to the item page
*/ */

View File

@ -27,7 +27,7 @@
export default { export default {
props: { props: {
value: [ String, Object, Array ], value: [ String, Object, Array ],
field: [ String, Object ], metadatum: [ String, Object ],
errors: [ String, Object, Array ] errors: [ String, Object, Array ]
}, },
data() { data() {

View File

@ -30,7 +30,7 @@
} }
}, },
props: { props: {
field: { metadatum: {
type: Object type: Object
}, },
options: { options: {
@ -44,9 +44,9 @@
if ( this.options && this.options !== '' ){ if ( this.options && this.options !== '' ){
return this.options.split("\n"); return this.options.split("\n");
} }
else if ( this.field && this.field.field.field_type_options.options ) { else if ( this.metadatum && this.metadatum.metadatum.metadatum_type_options.options ) {
const fields = this.field.field.field_type_options.options; const metadata = this.metadatum.metadatum.metadatum_type_options.options;
return ( fields ) ? fields.split("\n") : []; return ( metadata ) ? metadata.split("\n") : [];
} }
return []; return [];
} }

View File

@ -1,16 +1,16 @@
<?php <?php
namespace Tainacan\Field_Types; namespace Tainacan\Metadatum_Types;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/** /**
* Class TainacanFieldType * Class TainacanMetadatumType
*/ */
class Selectbox extends Field_Type { class Selectbox extends Metadatum_Type {
function __construct(){ function __construct(){
// call field type constructor // call metadatum type constructor
parent::__construct(); parent::__construct();
$this->set_primitive_type('string'); $this->set_primitive_type('string');
$this->set_component('tainacan-selectbox'); $this->set_component('tainacan-selectbox');
@ -37,18 +37,18 @@ class Selectbox extends Field_Type {
$options = $this->get_option('options'); $options = $this->get_option('options');
return '<tainacan-selectbox return '<tainacan-selectbox
options="' . $options . '" options="' . $options . '"
field_id ="'.$itemMetadata->get_field()->get_id().'" metadatum_id ="'.$itemMetadata->get_metadatum()->get_id().'"
item_id="'.$itemMetadata->get_item()->get_id().'" item_id="'.$itemMetadata->get_item()->get_id().'"
value=\''.json_encode( $itemMetadata->get_value() ).'\' 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 * @return array|bool true if is validate or array if has error
*/ */
public function validate_options(\Tainacan\Entities\Field $field) { public function validate_options(\Tainacan\Entities\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; return true;
if ( empty($this->get_option('options')) ) { if ( empty($this->get_option('options')) ) {

View File

@ -2,43 +2,43 @@
<b-field <b-field
:addons="false" :addons="false"
:message="getErrorMessage" :message="getErrorMessage"
:type="fieldTypeMessage"> :type="metadatumTypeMessage">
<span <span
class="collapse-handle" class="collapse-handle"
@click="$emit('changeCollapse', fieldTypeMessage != 'is-danger' ? !isCollapsed : true)"> @click="$emit('changeCollapse', metadatumTypeMessage != 'is-danger' ? !isCollapsed : true)">
<b-icon <b-icon
type="is-secondary" type="is-secondary"
:icon="isCollapsed || fieldTypeMessage == 'is-danger' ? 'menu-down' : 'menu-right'" /> :icon="isCollapsed || metadatumTypeMessage == 'is-danger' ? 'menu-down' : 'menu-right'" />
<label class="label">{{ field.field.name }}</label> <label class="label">{{ metadatum.metadatum.name }}</label>
<span <span
v-if="field.field.required == 'yes'" v-if="metadatum.metadatum.required == 'yes'"
class="required-field-asterisk" class="required-metadatum-asterisk"
:class="fieldTypeMessage">*</span> :class="metadatumTypeMessage">*</span>
<span class="field-type">({{ $i18n.get(field.field.field_type_object.component) }})</span> <span class="metadatum-type">({{ $i18n.get(metadatum.metadatum.metadatum_type_object.component) }})</span>
<help-button <help-button
:title="field.field.name" :title="metadatum.metadatum.name"
:message="field.field.description"/> :message="metadatum.metadatum.description"/>
</span> </span>
<div <div
v-show="isCollapsed || fieldTypeMessage == 'is-danger'" v-show="isCollapsed || metadatumTypeMessage == 'is-danger'"
v-if="isTextInputComponent( field.field.field_type_object.component )"> v-if="isTextInputComponent( metadatum.metadatum.metadatum_type_object.component )">
<component <component
:id="field.field.field_type_object.component + '-' + field.field.slug" :id="metadatum.metadatum.metadatum_type_object.component + '-' + metadatum.metadatum.slug"
:is="field.field.field_type_object.component" :is="metadatum.metadatum.metadatum_type_object.component"
v-model="inputs[0]" v-model="inputs[0]"
:field="field" :metadatum="metadatum"
@blur="changeValue()"/> @blur="changeValue()"/>
<div v-if="field.field.multiple == 'yes'"> <div v-if="metadatum.metadatum.multiple == 'yes'">
<div <div
v-if="index > 0" v-if="index > 0"
v-for="(input, index) in inputsList " v-for="(input, index) in inputsList "
:key="index" :key="index"
class="multiple-inputs"> class="multiple-inputs">
<component <component
:id="field.field.field_type_object.component + '-' + field.field.slug" :id="metadatum.metadatum.metadatum_type_object.component + '-' + metadatum.metadatum.slug"
:is="field.field.field_type_object.component" :is="metadatum.metadatum.metadatum_type_object.component"
v-model="inputs[index]" v-model="inputs[index]"
:field="field" :metadatum="metadatum"
@blur="changeValue()"/><a @blur="changeValue()"/><a
class="button" class="button"
v-if="index > 0" v-if="index > 0"
@ -53,10 +53,10 @@
v-show="isCollapsed" v-show="isCollapsed"
v-else> v-else>
<component <component
:id="field.field.field_type_object.component + '-' + field.field.slug" :id="metadatum.metadatum.metadatum_type_object.component + '-' + metadatum.metadatum.slug"
:is="field.field.field_type_object.component" :is="metadatum.metadatum.metadatum_type_object.component"
v-model="inputs" v-model="inputs"
:field="field" :metadatum="metadatum"
@blur="changeValue()"/> @blur="changeValue()"/>
</div> </div>
</b-field> </b-field>
@ -68,15 +68,15 @@
export default { export default {
name: 'TainacanFormItem', name: 'TainacanFormItem',
props: { props: {
field: { metadatum: {
type: Object type: Object
}, },
isCollapsed: true // Field Collapses isCollapsed: true // Metadatum Collapses
}, },
data(){ data(){
return { return {
inputs: [], inputs: [],
fieldTypeMessage:'' metadatumTypeMessage:''
} }
}, },
computed: { computed: {
@ -86,10 +86,10 @@
getErrorMessage() { getErrorMessage() {
let msg = ''; let msg = '';
let errors = eventBus.getErrors(this.field.field.id); let errors = eventBus.getErrors(this.metadatum.metadatum.id);
if ( errors) { if ( errors) {
this.setFieldTypeMessage('is-danger'); this.setMetadatumTypeMessage('is-danger');
for (let error of errors) { for (let error of errors) {
for (let index of Object.keys(error)) { for (let index of Object.keys(error)) {
// this.$console.log(index); // this.$console.log(index);
@ -97,7 +97,7 @@
} }
} }
} else { } else {
this.setFieldTypeMessage(''); this.setMetadatumTypeMessage('');
} }
return msg; return msg;
@ -108,15 +108,15 @@
}, },
methods: { methods: {
changeValue(){ 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(){ getValue(){
if (this.field.value instanceof Array) { if (this.metadatum.value instanceof Array) {
this.inputs = this.field.value; this.inputs = this.metadatum.value;
if (this.inputs.length === 0) if (this.inputs.length === 0)
this.inputs.push(''); this.inputs.push('');
} else { } 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(){ addInput(){
@ -131,8 +131,8 @@
let array = ['tainacan-relationship','tainacan-category']; let array = ['tainacan-relationship','tainacan-category'];
return !( array.indexOf( component ) >= 0 ); return !( array.indexOf( component ) >= 0 );
}, },
setFieldTypeMessage( message ){ setMetadatumTypeMessage( message ){
this.fieldTypeMessage = message; this.metadatumTypeMessage = message;
} }
} }
} }
@ -156,7 +156,7 @@
margin-left: 18px; margin-left: 18px;
margin-bottom: 0.5em; margin-bottom: 0.5em;
} }
.field-type { .metadatum-type {
font-size: 13px; font-size: 13px;
font-weight: 400; font-weight: 400;
color: $gray; color: $gray;

View File

@ -20,7 +20,7 @@
} }
}, },
props: { props: {
field: { metadatum: {
type: Object type: Object
}, },
value: [String, Number, Array], value: [String, Number, Array],

View File

@ -1,16 +1,16 @@
<?php <?php
namespace Tainacan\Field_Types; namespace Tainacan\Metadatum_Types;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/** /**
* Class TainacanFieldType * Class TainacanMetadatumType
*/ */
class Text extends Field_Type { class Text extends Metadatum_Type {
function __construct(){ function __construct(){
// call field type constructor // call metadatum type constructor
parent::__construct(); parent::__construct();
parent::set_primitive_type('string'); parent::set_primitive_type('string');
parent::set_component('tainacan-text'); parent::set_component('tainacan-text');
@ -22,9 +22,9 @@ class Text extends Field_Type {
*/ */
public function render( $itemMetadata ){ 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().'" item_id="'.$itemMetadata->get_item()->get_id().'"
value=\''.json_encode( $itemMetadata->get_value() ).'\' value=\''.json_encode( $itemMetadata->get_value() ).'\'
name="'.$itemMetadata->get_field()->get_name().'"></tainacan-text>'; name="'.$itemMetadata->get_metadatum()->get_name().'"></tainacan-text>';
} }
} }

View File

@ -23,7 +23,7 @@
}, },
props: { props: {
id: '', id: '',
field: { metadatum: {
type: Object type: Object
}, },
value: [String, Number, Array], value: [String, Number, Array],

Some files were not shown because too many files have changed in this diff Show More