Commit 9f8419cd authored by Andre Togawa's avatar Andre Togawa
Browse files

Merge branch '220330-block-name-change' into 'master'

First commit

See merge request !1
<?php return array('dependencies' => array('wp-element'), 'version' => '3c7be91edd829a1f8440f4f3f039f5bc');
\ No newline at end of file
/******/ (function() { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "@wordpress/element":
/*!*********************************!*\
!*** external ["wp","element"] ***!
\*********************************/
/***/ (function(module) {
module.exports = window["wp"]["element"];
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ !function() {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function() { return module['default']; } :
/******/ function() { return module; };
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ !function() {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = function(exports, definition) {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ !function() {
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
/******/ }();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ !function() {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ }();
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
!function() {
/*!**********************!*\
!*** ./src/index.js ***!
\**********************/
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__);
const {
registerBlockType
} = wp.blocks;
const {
__
} = wp.i18n;
const {
InnerBlocks,
InspectorControls,
ColorPalette
} = wp.blockEditor;
const ALLOWED_BLOCKS_GROUP = ['core/group']; //== Block GetOD:Text ==//
registerBlockType('getod/getod-text', {
title: 'GetOD: Text',
description: 'Get text from metadata ID',
icon: 'rest-api',
category: 'common',
attributes: {
GetOD_text: {
type: "string"
}
},
edit: function (props) {
function updateText(event) {
props.setAttributes({
GetOD_text: event.target.value
});
}
return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", null, "GetOD | Text: ", (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("input", {
type: "text",
placeholder: "MetadataID",
value: props.attributes.GetOD_text,
onChange: updateText
}));
},
save: function () {
return null;
}
}); //== Block GetOD:Image ==//
registerBlockType('getod/getod-image', {
title: 'GetOD: Image',
description: 'Get image from metadata ID',
icon: 'rest-api',
category: 'common',
attributes: {
GetOD_image: {
type: "string"
}
},
edit: function (props) {
function updateImage(event) {
props.setAttributes({
GetOD_image: event.target.value
});
}
return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", null, "GetOD | Image: ", (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("input", {
type: "text",
placeholder: "MetadataID",
value: props.attributes.GetOD_image,
onChange: updateImage
}));
},
save: function () {
return null;
}
}); //== Block GetOD:Video ==//
registerBlockType('getod/getod-video', {
title: 'GetOD: Video',
description: 'Get video from metadata ID',
icon: 'rest-api',
category: 'common',
attributes: {
GetOD_video: {
type: "string"
}
},
edit: function (props) {
function updateVideo(event) {
props.setAttributes({
GetOD_video: event.target.value
});
}
return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", null, "GetOD | Video: ", (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("input", {
type: "text",
placeholder: "MetadataID",
value: props.attributes.GetOD_video,
onChange: updateVideo
}));
},
save: function () {
return null;
}
}); //== Block GetOD: Audio ==//
registerBlockType('getod/getod-audio', {
title: 'GetOD: Audio',
description: 'Get Audio from metadata ID',
icon: 'rest-api',
category: 'common',
attributes: {
GetOD_audio: {
type: "string"
}
},
edit: function (props) {
function updateAudio(event) {
props.setAttributes({
GetOD_audio: event.target.value
});
}
return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", null, "GetOD | Audio: ", (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("input", {
type: "text",
placeholder: "MetadataID",
value: props.attributes.GetOD_audio,
onChange: updateAudio
}));
},
save: function () {
return null;
}
}); //== Block GetOD: MiniLoop
registerBlockType('getod/getod-miniloop', {
title: 'GetOD: Miniloop',
description: 'Bloco Miniloop, Insira um MetadataID, um loop povando os blocos dentro deste bloco irá ser realizado.',
icon: 'rest-api',
category: 'common',
attributes: {
GetOD_Miniloop: {
type: "string"
}
},
edit: function (props) {
function updateMiniloop(event) {
props.setAttributes({
GetOD_Miniloop: event.target.value
});
}
return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
className: "omeka-plugin-interno-border"
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
className: "omeka-aplugin-interno-comentrio"
}, "GetOD | Miniloop: ", (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("input", {
type: "text",
placeholder: "MetadataID",
value: props.attributes.GetOD_Miniloop,
onChange: updateMiniloop
}), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("br", null), "--------------------"), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(InnerBlocks, {
allowedBlocks: ALLOWED_BLOCKS_GROUP
}));
},
save: function (props) {
return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
class: "getod-miniloop",
metadata_id: props.attributes.GetOD_Miniloop
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
className: "getod-miniloop-empty"
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(InnerBlocks.Content, null))));
}
}); //== Block GetOD: ItemSetLoop
registerBlockType('getod/getod-itemsetloop', {
title: 'GetOD: ItemSetLoop',
description: 'Bloco para gerar loop com lista de itens',
icon: 'rest-api',
category: 'common',
attributes: {
itensPerPage: {
type: "string"
},
ItemSetID: {
type: "string"
}
},
edit: function (props) {
function updateItemSetID(event) {
props.setAttributes({
ItemSetID: event.target.value
});
}
function updateItensPerPage(event) {
props.setAttributes({
itensPerPage: event.target.value
});
}
return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
className: "omeka-plugin-interno-border"
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
className: "omeka-aplugin-interno-comentrio"
}, "GetOD | Item Set Loop", (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("br", null), "GetOD | Item Set ID: ", (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("input", {
type: "text",
placeholder: "Set ID",
value: props.attributes.ItemSetID,
onChange: updateItemSetID
}), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("br", null), "GetOD | Item per Page: ", (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("input", {
type: "text",
placeholder: "Set ID",
value: props.attributes.itensPerPage,
onChange: updateItensPerPage
}), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("br", null), "--------------------"), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(InnerBlocks, {
allowedBlocks: ALLOWED_BLOCKS_GROUP
}));
},
save: function (props) {
return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
class: "getod-itemsetloop dot-pulse",
getod_block: "getod-ItemSetLoop",
getod_item_set_id: props.attributes.ItemSetID,
getod_items_per_page: props.attributes.itensPerPage
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
className: "getod-itemsetloop-empty"
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(InnerBlocks.Content, null))));
}
}); //== Block GetOD: ItemSetLoop-url
registerBlockType('getod/getod-itemsetloop-url', {
title: 'GetOD: ItemSetLoop-Url',
description: 'Bloco para adicionar link para página',
icon: 'rest-api',
category: 'common',
attributes: {
UrlPage: {
type: "string"
}
},
edit: function (props) {
function updateUrlPage(event) {
props.setAttributes({
UrlPage: event.target.value
});
}
return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
className: "omeka-plugin-interno-border"
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
className: "omeka-aplugin-interno-comentrio"
}, "GetOD | Url page: ", (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("input", {
type: "text",
placeholder: "Url Page",
value: props.attributes.UrlPage,
onChange: updateUrlPage
}), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("br", null), "--------------------"), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(InnerBlocks //allowedBlocks={ ALLOWED_BLOCKS_ALL }
, null));
},
save: function (props) {
return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
className: "getod getod-item-set-url getod-empty",
getod_block: "getod-item-set-url"
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("a", {
href: props.attributes.UrlPage
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(InnerBlocks.Content, null))));
}
}); //== Block GetOD: Pagination
registerBlockType('getod/getod-pagination', {
title: 'GetOD: Pagination',
description: 'Bloco para adicionar próxima página e página anterior. Deverá ser usado apenas na pagina que possui GetOD: itemsetloop',
icon: 'rest-api',
category: 'common',
attributes: {
UrlPage: {
type: "string"
},
gotopage: {
type: "string",
default: 'next_page'
}
},
edit: function (props) {
const {
attributes: {
gotopage
},
setAttributes
} = props;
function setGoto(event) {
props.setAttributes({
gotopage: event.target.value
});
event.preventDefault();
} // function getParameterByName(name, url = window.location.href) {
// name = name.replace(/[\[\]]/g, '\\$&');
// var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
// results = regex.exec(url);
// if (!results) return null;
// if (!results[2]) return '';
// return decodeURIComponent(results[2].replace(/\+/g, ' '));
// }
// function retunURL(parameter){
// props.setAttributes({UrlPage: 'teste'})
// }
return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
className: "omeka-plugin-interno-border"
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
className: "omeka-aplugin-interno-comentrio"
}, "GetOD | Pagination:", (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("select", {
value: gotopage,
onChange: setGoto
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("option", {
value: "next_page"
}, "Pr\xF3xima P\xE1gina"), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("option", {
value: "previous_page"
}, "P\xE1gina Anterior")), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("br", null), "--------------------"), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(InnerBlocks, null));
},
save: function (props) {
return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
className: "getod getod-pagination getod-empty",
getod_block: "pagination",
getod_pag_type: props.attributes.gotopage
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("a", {
href: "google.com"
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(InnerBlocks.Content, null))));
}
});
}();
/******/ })()
;
//# sourceMappingURL=index.js.map
\ No newline at end of file
This diff is collapsed.
<?php
/**
* @package GetOmekaData
*/
/*
Plugin Name: Get Omeka Data
Description: Add Omeka API data and inject using wordpress blocks
Version: 1.0.0
Author: IBICT | André Togawa
*/
defined( 'ABSPATH' ) or die( 'Hi there! I\'m just a plugin, not much I can do when called directly.' );
if (!class_exists('GetOmekaData')){
class GetOmekaData{
public $pluginName;
// == On Plugin running == //
function __construct(){
$this->pluginName = plugin_basename( __FILE__ );
//add_action ('init', array($this, 'custom_post_type'));
add_action( 'admin_init', array($this,'settingsOptions'));
add_action( 'init', array($this,'getod_gutenberg_blocks'));
add_action( 'wp_enqueue_scripts', array($this,'load_js_css'));
}
function load_js_css() {
$plugin_url = plugin_dir_url( __FILE__ );
wp_enqueue_style( 'style1', $plugin_url . '/inc/mystyle.css' );
wp_enqueue_script( 'test-js', $plugin_url . 'js/on_page_load.js');
}
// == Gutenberg Functions ==//
function getod_gutenberg_blocks(){
wp_register_script( 'getod-blocks-js', plugins_url('/build/index.js', __FILE__ ), array('wp-blocks', 'wp-block-editor', 'wp-components'));
register_block_type( 'getod/getod-text', array('editor_script' => 'getod-blocks-js', 'render_callback' => array($this,'GetOD_text_html')));
register_block_type( 'getod/getod-image', array('editor_script' => 'getod-blocks-js', 'render_callback' => array($this,'GetOD_image_html')));
register_block_type( 'getod/getod-video', array('editor_script' => 'getod-blocks-js', 'render_callback' => array($this,'GetOD_video_html')));
register_block_type( 'getod/getod-audio', array('editor_script' => 'getod-blocks-js', 'render_callback' => array($this,'GetOD_audio_html')));
}
function GetOD_text_html($attributes){
if ($attributes['GetOD_text']){
return '<div class="getod getod-text getod-empty dot-pulse" metadata_id="' . $attributes['GetOD_text'] . '"getod_block ="getod-text"></div>';
}
}
function GetOD_image_html($attributes){
if ($attributes['GetOD_image']){
return '<div class="getod getod-image getod-empty dot-pulse" metadata_id="' . $attributes['GetOD_image'] . '"getod_block ="getod-image"></div>';
}
}
function GetOD_video_html($attributes){
if ($attributes['GetOD_video']){
return '<div class="getod getod-video getod-empty dot-pulse" metadata_id="' . $attributes['GetOD_video'] . '"getod_block ="getod-video"></div>';
}
}
function GetOD_audio_html($attributes){
if ($attributes['GetOD_audio']){
return '<div class="getod getod-audio getod-empty dot-pulse" metadata_id="' . $attributes['GetOD_audio'] . '" getod_block ="getod-audio"></div>';
}
}
// == Add Admin page == //
public function add_admin_pages(){
add_menu_page( 'GetOD', 'GetOD', 'manage_options', 'GetOD_plugin', array($this,'admin_index'),'dashicons-rest-api', 110);
}
// == Plugin admin page == //
public function admin_index(){
require_once plugin_dir_path( __FILE__ ) . 'inc/get_od_admin_page.php';
}
function settingsOptions(){
add_settings_section( 'getod_first_section', null, null, 'GetOD' );
//criando pagina com os dados para pagina
add_settings_field( 'getod_url_api', 'Url da API', array($this,'paginaHTML'), 'GetOD', 'getod_first_section');
register_setting( 'getod_url', 'getod_url_api', array('sanitize_callback'=>'sanitize_text_field') );
}
function paginaHTML(){?>
<input type="text" name="getod_url_api" value="<?php echo esc_attr( get_option('getod_url_api') ) ?>">
<?php }
// == On Plugin Activation == //
function activate (){
require_once plugin_dir_path( __FILE__ ) . 'inc/get_od_activate.php';
GetODActivate::activate();
}
// == Register on Acivation == //
function register(){
add_action( 'admin_menu', array( $this, 'add_admin_pages') ); // Add Admin button to menu
add_action ('admin_enqueue_scripts', array($this,'enqueue')); // add css page on admin side
}
function enqueue(){
// enqueue all our scripts
wp_enqueue_style( 'mypluginstyle', plugins_url('/inc/mystyle.css', __FILE__ ) );
}
}
if ( class_exists( 'GetOmekaData')){
$GetOmekaData = new GetOmekaData();
$GetOmekaData->register();
}
// activation
register_activation_hook( __FILE__, array($GetOmekaData, 'activate'));
// deactivation
require_once plugin_dir_path( __FILE__ ) . 'inc/get_od_deactivate.php';
register_deactivation_hook( __FILE__, array('GetODDeactivate', 'deactivate'));
}
<?php
class GetODActivate
{
public static function activate(){
flush_rewrite_rules( );
}
}
\ No newline at end of file
<div class="wrap">
<h1>Get Omeka Data</h1>
Shotcodes:
<br>
[notaveis_lista] => mostra a lista de notaveis.
[ver_notavel] => mostra o notavel. Ele vai puxar do url o "id_notavel"
<form action="options.php" method="POST">
<?php
settings_fields('getod_url');
do_settings_sections('GetOD');
submit_button();
?>
</form>
</div>
<?php
class GetODDeactivate
{
public static function deactivate(){
flush_rewrite_rules( );
}
}
\ No newline at end of file
.omeka-plugin-interno-border{
border: 1px dashed rgb(78, 78, 78);
padding: 10px;
}
.omeka-plugin-interno-comentario{
font-size: 0.7em;
color: red;
font-weight: bold;
}
.omeka-loop{
display: none;
}
.getod-miniloop-empty,
.getod-itemsetloop-empty{
display: none;
}
/* dot pulse https://codepen.io/nzbin/pen/GGrXbp */
.dot-pulse {
position: relative;
left: -9999px;
width: 10px;
height: 10px;
border-radius: 5px;
background-color:#000;
color: #000;
box-shadow: 9999px 0 0 -5px #000;
animation: dotPulse 1.5s infinite linear;
animation-delay: .25s;
}
.dot-pulse::before, .dot-pulse::after {
content: '';
display: inline-block;
position: absolute;
top: 0;
width: 10px;
height: 10px;
border-radius: 5px;
background-color: #000;
color: #000;
}
.dot-pulse::before {
box-shadow: 9984px 0 0 -5px #000;
animation: dotPulseBefore 1.5s infinite linear;
animation-delay: 0s;
}
.dot-pulse::after {
box-shadow: 10014px 0 0 -5px #000;
animation: dotPulseAfter 1.5s infinite linear;
animation-delay: .5s;
}
@keyframes dotPulseBefore {
0% {
box-shadow: 9984px 0 0 -5px #000;
}
30% {
box-shadow: 9984px 0 0 2px #000;
}
60%,
100% {
box-shadow: 9984px 0 0 -5px #000;
}
}
@keyframes dotPulse {
0% {
box-shadow: 9999px 0 0 -5px #000;
}
30% {
box-shadow: 9999px 0 0 2px #000;
}
60%,
100% {
box-shadow: 9999px 0 0 -5px #000;
}
}
@keyframes dotPulseAfter {
0% {
box-shadow: 10014px 0 0 -5px #000;
}
30%{
box-shadow: 10014px 0 0 2px #000;
}
60%,
100% {
box-shadow: 10014px 0 0 -5px #000;
}
}
/* END dot pulse https://codepen.io/nzbin/pen/GGrXbp */
\ No newline at end of file
<?php
// Silence is golden.
// para testar http://192.168.1.112/togas/?p=150/?item_id=22860
// == Set API Data ==//
var API_url = 'https://repositorio.canalciencia.ibict.br/api';
var item_id = getParameterByName('item_id');
var page = getParameterByName('page');
if(page == null){
page=1;
}
var runFetch= false;
window.addEventListener('load', function () {
if (item_id){
var requestURL = API_url + '/items/'+ item_id;
var pageType = 'itemPage';
runFetch= true;
}
else{
var divItemLoop = document.getElementsByClassName('getod-itemsetloop');
if (divItemLoop.length>0) {
var itemSetID = divItemLoop[0].getAttribute("getod_item_set_id");
var itemPerPage = divItemLoop[0].getAttribute("getod_items_per_page");
console.log('Loading Item Set '+itemSetID);
var requestURL = API_url + '/items?item_set_id[]=' + itemSetID +'&per_page='+itemPerPage+'&page='+page;
console.log(requestURL)
var pageType = 'listPage';
runFetch= true;
}
setPagination();
}
// == Load API DATA ==//
if(runFetch){
fetch(requestURL)
.then(function (response) {
return response.json();
})
.then(function (jasonData) {
// remover imagem de load
loaderElements = document.getElementsByClassName('dot-pulse');
while(loaderElements.length > 0){
loaderElements[0].classList.remove("dot-pulse")
}
if (pageType == 'itemPage'){
//First find all MiniLoop and populate
PopulateMiniLoop(jasonData);
//then find all divs with getod-empty and populate
divItem = document.getElementsByClassName('getod-empty');
PopulateFields(jasonData, divItem);
}
else {
//If there is a Item Set Loop
PopulateSetLoop(jasonData);
}
})
.catch(function (err) {
console.log("Something went wrong!", err);
});
}
})
// == MiniLoop Functions ==//
function PopulateMiniLoop(jasonData){
var divItem = document.getElementsByClassName('getod-miniloop');
divItemLength = divItem.length;
for (var i = 0; i < divItemLength; ++i) {
var attributeName = divItem[0].getAttribute("metadata_id"); //divItem[0] em vez de i porque quando remove a classe o array reduz
for (var j = 0; j < jasonData[attributeName].length; j++) {
cloneDivID(divItem[0]);
renameClass('getod-miniloop-clone', ""+i+j)
var divGetODloop = document.querySelectorAll('.getod-miniloop-clone-'+i+j);
var divSingleItem = divGetODloop[0].querySelectorAll('.getod-empty');
PopulateFields(jasonData[attributeName][j], divSingleItem,true)
}
divItem[0].classList.remove("getod-miniloop");// aqui eu tiro a classe getod-miniloop e o array divItem reduz também em 1;
}
}
function cloneDivID(idTermo){
// clone all content from ID
// obtem o elemento com o id especificado
var div_loop = idTermo;
// pegando o conteudo do primeiro elemento que é o que contem o template.
var conteudo = div_loop.firstChild;
// Clonar o elemento
var conteudo_clonado = conteudo.cloneNode(true);
if (conteudo_clonado.classList.contains('getod-miniloop-empty')){
conteudo_clonado.classList.add('getod-miniloop-clone');
conteudo_clonado.classList.remove('getod-miniloop-empty');
}
else if (conteudo_clonado.classList.contains('getod-itemsetloop-empty')) {
conteudo_clonado.classList.add('getod-itemsetloop-clone');
conteudo_clonado.classList.remove('getod-itemsetloop-empty');
}
div_loop.appendChild(conteudo_clonado);
}
function renameClass(classe, numero){
// renomeia o último item da classe adicionando um numero
const last = Array.from(
document.querySelectorAll("."+classe)
).pop();
last.classList.remove(classe);
last.classList.add(classe+"-"+numero);
}
// == ItemSetLoop Functions ==//
function PopulateSetLoop(jasonData){
var divItem = document.getElementsByClassName('getod-itemsetloop');
divItemLength = jasonData.length;
for (let i = 0; i < divItemLength; ++i) {
var attributeName = divItem[0].getAttribute("metadata_id"); //divItem[0] em vez de i porque quando remove a classe o array reduz
cloneDivID(divItem[0]);
renameClass('getod-itemsetloop-clone', ""+i)
var divGetODloop = document.querySelectorAll('.getod-itemsetloop-clone-'+i);
var divSingleItem = divGetODloop[0].querySelectorAll('.getod-empty');
PopulateFields(jasonData[i], divSingleItem)
divItem[0].classList.remove("getod-miniloop");// aqui eu tiro a classe getod-miniloop e o array divItem reduz também em 1;
// se tiver um link
var divSingleItem = divGetODloop[0].querySelectorAll('div.getod-item-set-url a');
if (divSingleItem.length>0){
aUrl= divSingleItem[0].getAttribute("href");
divSingleItem[0].href= aUrl +'?item_id='+ jasonData[i]['o:id'];
}
}
}
// == Populate all fields ==//
function PopulateFields(jasonData, divItem, miniLoop){
//deve receber uma lista de divs com a classe getod-empty, depois pegar o valor do metadado e injetar a informacao dentro desse div
// divItem tem que ser uma lista de divs com classe .getod-empty
if (miniLoop === undefined){
miniLoop = false;
}
for (let i = 0; i < divItem.length; ++i) {
var item = divItem[i];
attribute = item.getAttribute("metadata_id");
GetODBlock = item.getAttribute("getod_block");
if(miniLoop){ // if inside MiniLoop
if (attribute){
value = jasonData[attribute];
item.innerHTML = value;
item.classList.remove("getod-empty");
}
}
else{ // if not in MiniLoop
value = jasonData[attribute];
valueForAttribute = getValueForAttribute(value);
if (GetODBlock == 'getod-text'){
item.innerHTML = valueForAttribute;
}
if (GetODBlock == 'getod-image'){
item.appendChild(document.createElement('img')).src = valueForAttribute
}
if (GetODBlock == 'getod-video'){
//não implementado
}
if (GetODBlock == 'getod-audio'){
//não implementado
}
}
}
}
// == the the values from omeka atributes ==//
function getValueForAttribute(atributo){
let value = '';
if (atributo){
let tipo="";
if (atributo.length >0){
if (atributo[0].hasOwnProperty('type')) {
tipo = atributo[0]['type'];
}
}
else{
if (atributo.hasOwnProperty('large')) {
value = atributo['large'];
}
}
if (tipo == 'resource:media') {
if (atributo[0].hasOwnProperty('thumbnail_url')) {
value = atributo[0]['thumbnail_url'];
}
}
if (tipo == 'literal' || tipo == 'numeric:timestamp' || tipo == 'customvocab:18') {
if (atributo[0].hasOwnProperty('@value')) {
value = atributo[0]['@value'];
}
}
}
return value;
}
// == get parameters from url ==//
function getParameterByName(name, url = window.location.href) {
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
// == Ajust pagination url ==//
function setPagination(){
divPagination = document.querySelectorAll('div.getod-pagination');
for (let i = 0; i < divPagination.length; ++i) {
pageType = divPagination[i].getAttribute("getod_pag_type");
divA = divPagination[i].querySelectorAll('a')
let currentUrl = window.location.href;
let currentpage = getParameterByName('page');
if(pageType == 'next_page'){
if(currentpage != null){
newUrl = replaceQueryParam('page', Number(currentpage)+1, currentUrl);
}
else{
newUrl = currentUrl + '?page=2'
}
}
else{
if(currentpage >1 ){
newUrl = replaceQueryParam('page', Number(currentpage)-1, currentUrl);
}
else{
newUrl = currentUrl + '?page=1'
divA[0].remove();
}
}
divA[0].href = newUrl;
}
}
function replaceQueryParam(param, newval, search) {
var regex = new RegExp("([?;&])" + param + "[^&;]*[;&]?");
var query = search.replace(regex, "$1").replace(/&$/, '');
// return (query.length > 2 ? query + "&" : "?") + (newval ? param + "=" + newval : ''); // original
return (query) + (newval ? param + "=" + newval : '');
}
alert('oi');
\ No newline at end of file
This diff is collapsed.
{
"name": "get-omeka-data",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "wp-scripts build",
"start": "wp-scripts start",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@wordpress/scripts": "^22.3.0"
}
}
const { registerBlockType } = wp.blocks;
const { __ } = wp.i18n;
const { InnerBlocks, InspectorControls, ColorPalette } = wp.blockEditor;
const ALLOWED_BLOCKS_GROUP = ['core/group'];
//== Block GetOD:Text ==//
registerBlockType('getod/getod-text', {
title: 'GetOD: Text',
description: 'Get text from metadata ID',
icon: 'rest-api',
category: 'common',
attributes: {
GetOD_text: {type: "string" }
},
edit: function(props){
function updateText(event){
props.setAttributes({GetOD_text: event.target.value})
}
return (
<div>
GetOD | Text: <input type="text" placeholder="MetadataID" value={props.attributes.GetOD_text} onChange={updateText} />
</div>
)
},
save: function(){
return null
},
});
//== Block GetOD:Image ==//
registerBlockType('getod/getod-image', {
title: 'GetOD: Image',
description: 'Get image from metadata ID',
icon: 'rest-api',
category: 'common',
attributes: {
GetOD_image: {type: "string" }
},
edit: function(props){
function updateImage(event){
props.setAttributes({GetOD_image: event.target.value})
}
return (
<div>
GetOD | Image: <input type="text" placeholder="MetadataID" value={props.attributes.GetOD_image} onChange={updateImage} />
</div>
)
},
save: function(){
return null
},
});
//== Block GetOD:Video ==//
registerBlockType('getod/getod-video', {
title: 'GetOD: Video',
description: 'Get video from metadata ID',
icon: 'rest-api',
category: 'common',
attributes: {
GetOD_video: {type: "string" }
},
edit: function(props){
function updateVideo(event){
props.setAttributes({GetOD_video: event.target.value})
}
return (
<div>
GetOD | Video: <input type="text" placeholder="MetadataID" value={props.attributes.GetOD_video} onChange={updateVideo} />
</div>
)
},
save: function(){
return null
},
});
//== Block GetOD: Audio ==//
registerBlockType('getod/getod-audio', {
title: 'GetOD: Audio',
description: 'Get Audio from metadata ID',
icon: 'rest-api',
category: 'common',
attributes: {
GetOD_audio: {type: "string" }
},
edit: function(props){
function updateAudio(event){
props.setAttributes({GetOD_audio: event.target.value})
}
return (
<div>
GetOD | Audio: <input type="text" placeholder="MetadataID" value={props.attributes.GetOD_audio} onChange={updateAudio} />
</div>
)
},
save: function(){
return null
},
});
//== Block GetOD: MiniLoop
registerBlockType('getod/getod-miniloop', {
title: 'GetOD: Miniloop',
description: 'Bloco Miniloop, Insira um MetadataID, um loop povando os blocos dentro deste bloco irá ser realizado.',
icon: 'rest-api',
category: 'common',
attributes: {
GetOD_Miniloop: {type: "string" }
},
edit: function(props){
function updateMiniloop(event){
props.setAttributes({GetOD_Miniloop: event.target.value})
}
return (
<div className="omeka-plugin-interno-border">
<div className="omeka-aplugin-interno-comentrio">
GetOD | Miniloop: <input type="text" placeholder="MetadataID" value={props.attributes.GetOD_Miniloop} onChange={updateMiniloop} />
<br></br>
--------------------
</div>
<InnerBlocks
allowedBlocks={ ALLOWED_BLOCKS_GROUP }
/>
</div>
)
},
save: function(props){
return (
<>
<div class="getod-miniloop" metadata_id={props.attributes.GetOD_Miniloop}>
<div className="getod-miniloop-empty" >
<InnerBlocks.Content/>
</div>
</div>
</>
)
},
});
//== Block GetOD: ItemSetLoop
registerBlockType('getod/getod-itemsetloop', {
title: 'GetOD: ItemSetLoop',
description: 'Bloco para gerar loop com lista de itens',
icon: 'rest-api',
category: 'common',
attributes: {
itensPerPage: {type: "string" },
ItemSetID: {type: "string" }
},
edit: function(props){
function updateItemSetID(event){
props.setAttributes({ItemSetID: event.target.value})
}
function updateItensPerPage(event){
props.setAttributes({itensPerPage: event.target.value})
}
return (
<div className="omeka-plugin-interno-border">
<div className="omeka-aplugin-interno-comentrio">
GetOD | Item Set Loop
<br></br>
GetOD | Item Set ID: <input type="text" placeholder="Set ID" value={props.attributes.ItemSetID} onChange={updateItemSetID} />
<br></br>
GetOD | Item per Page: <input type="text" placeholder="Set ID" value={props.attributes.itensPerPage} onChange={updateItensPerPage} />
<br></br>
--------------------
</div>
<InnerBlocks
allowedBlocks={ ALLOWED_BLOCKS_GROUP }
/>
</div>
)
},
save: function(props){
return (
<>
<div class="getod-itemsetloop dot-pulse" getod_block ="getod-ItemSetLoop" getod_item_set_id = {props.attributes.ItemSetID} getod_items_per_page = {props.attributes.itensPerPage}>
<div className="getod-itemsetloop-empty" >
<InnerBlocks.Content/>
</div>
</div>
</>
)
},
});
//== Block GetOD: ItemSetLoop-url
registerBlockType('getod/getod-itemsetloop-url', {
title: 'GetOD: ItemSetLoop-Url',
description: 'Bloco para adicionar link para página',
icon: 'rest-api',
category: 'common',
attributes: {
UrlPage: {type: "string" }
},
edit: function(props){
function updateUrlPage(event){
props.setAttributes({UrlPage: event.target.value})
}
return (
<div className="omeka-plugin-interno-border">
<div className="omeka-aplugin-interno-comentrio">
GetOD | Url page: <input type="text" placeholder="Url Page" value={props.attributes.UrlPage} onChange={updateUrlPage} />
<br></br>
--------------------
</div>
<InnerBlocks
//allowedBlocks={ ALLOWED_BLOCKS_ALL }
/>
</div>
)
},
save: function(props){
return (
<>
<div className="getod getod-item-set-url getod-empty" getod_block ="getod-item-set-url">
<a href= {props.attributes.UrlPage} >
<InnerBlocks.Content/>
</a>
</div>
</>
)
},
});
//== Block GetOD: Pagination
registerBlockType('getod/getod-pagination', {
title: 'GetOD: Pagination',
description: 'Bloco para adicionar próxima página e página anterior. Deverá ser usado apenas na pagina que possui GetOD: itemsetloop',
icon: 'rest-api',
category: 'common',
attributes: {
UrlPage: {type: "string" },
gotopage: {type: "string", default: 'next_page'}
},
edit: function(props){
const {attributes: {gotopage}, setAttributes} = props;
function setGoto(event){
props.setAttributes({gotopage: event.target.value})
event.preventDefault();
}
// function getParameterByName(name, url = window.location.href) {
// name = name.replace(/[\[\]]/g, '\\$&');
// var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
// results = regex.exec(url);
// if (!results) return null;
// if (!results[2]) return '';
// return decodeURIComponent(results[2].replace(/\+/g, ' '));
// }
// function retunURL(parameter){
// props.setAttributes({UrlPage: 'teste'})
// }
return (
<div className="omeka-plugin-interno-border">
<div className="omeka-aplugin-interno-comentrio">
GetOD | Pagination:
<select value={gotopage} onChange={ setGoto }>
<option value="next_page">Próxima Página</option>
<option value="previous_page">Página Anterior</option>
</select>
<br></br>
--------------------
</div>
<InnerBlocks
/>
{/* <InspectorControls key="setting">
<div id="gutenpride-controls">
<fieldset>
<legend className="blocks-base-control__label">
{ __( 'Background color', 'getod' ) }
</legend>
</fieldset>
</div>
</InspectorControls> */}
</div>
)
},
save: function(props){
return (
<>
<div className="getod getod-pagination getod-empty" getod_block ="pagination" getod_pag_type={props.attributes.gotopage}>
<a href="google.com">
<InnerBlocks.Content/>
</a>
</div>
</>
)
},
});
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment