Prechádzať zdrojové kódy

metqadati work in progress

cek 8 rokov pred
rodič
commit
bd4757d83e

+ 8 - 0
arav_up_api/index.php

@@ -88,6 +88,14 @@ function parseRequest() {
             $requestHandler = new arkiwiRequestPostUpload($request);
             break;
 
+        case 'listmetadata':
+            require_once './requests/requestGetListMetadata.php';
+            $requestHandler = new arkiwiRequestGetListMetadata($request);
+            break;
+
+
+
+
         case 'addmetadata':
             require_once './requests/requestPostMetadata.php';
             $requestHandler = new arkiwiRequestPostMetadata($request);

+ 37 - 0
arav_up_api/requests/requestGetListMetadata.php

@@ -0,0 +1,37 @@
+<?php
+require_once('request.php');
+
+class arkiwiRequestGetListMetadata extends arkiwiRequest
+{
+    private $item64 = null;
+
+    public function __construct($request) {
+        parent::__construct($request);
+        $extra = $this->getRequestExtra();
+
+        $this->item64 = $extra[0];
+    }
+
+    public function run() {
+        if($this->request['method'] != 'GET') {
+            $this->setBodyError(500, "arkiwiRequestPostMetadata: POST method required.");
+            return;
+        }
+
+
+        //INIZIO CAZZACCROCCHIO
+        //lo rimuoveremo quando H si decide a scrivere la parte che legge metadati anche nell'uploader
+
+        $items = array();
+        $metadata = file_get_contents($GLOBALS["conf"]["assetstore_endpoint"]."/item64/".$this->item64."/direct");
+        $metadata = simplexml_load_string($metadata)->xpath("/item/*");
+        for ($i = 0; $i < count($metadata); $i++) {
+            $items[] = array($metadata[$i]->getName(), $metadata[$i]->__toString());
+        }
+
+        //FINE CAZZACCROCCHIO
+
+        $this->setCode(201);
+        $this->setBodyJSON(print_r($items));
+    }
+}

+ 71 - 0
arav_up_client/edit.php

@@ -0,0 +1,71 @@
+<?php
+    // includes
+    $includePath = array();
+    $includePath[] = '../arav_up_inclu';
+    $includePath[] = get_include_path();
+    $includePath = implode(PATH_SEPARATOR,$includePath);
+    set_include_path($includePath);
+
+    require '../arav_up_confs.php';
+    require_once('auth.php');
+    require_once('report.php');
+
+    // presenta auth
+    if (!isset($_SERVER['PHP_AUTH_USER'])) {
+         prompt_auth();
+    //     report(1,"PHP_AUTH_USER not set, exiting"); //Lo vogliamo davvero loggare?
+         exit;
+    }
+
+    $authstate = do_local_auth($_SERVER['PHP_AUTH_USER'], hash("sha256",$_SERVER['PHP_AUTH_PW']));
+    // report(1,"userid : ".$authstate["userid"]);
+    // report(1,"dir : ".$authstate["dir"]);
+    if ($authstate["esito"] != "AUTH_OK") {
+    //     // es: is_inside_dir($object, $authstate["dir"]);
+        prompt_auth();
+    //     report(1,"esito not AUTH_OK, exiting");
+        exit;
+    }
+
+    // -----------------
+
+    parse_str($_SERVER['QUERY_STRING'], $query);
+
+    // I am not afraid of errors:
+    error_reporting(E_ALL);
+?>
+<!DOCTYPE html>
+<html>
+
+<head>
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+    <title>Arkiwi uploader</title>
+    <meta name="description" content="">
+
+    <script src="/arav_up_client/bower_components/jquery/dist/jquery.js"></script>
+    <script src="/arav_up_client/scripts/arkiwi.js"></script>
+    <script src="/arav_up_client/scripts/main.js"></script>
+
+</head>
+
+<body>
+
+    <form id="file-form" method="POST">
+        <p>Pippone con spiegone, si può anche mettere da un'altra parte, CRI vedi tu quando fai grafica</p>
+        <div id="metadata_container">
+        </div>
+    </form>
+
+    <input type="hidden" id="document-type" value="<?php echo $query['type']; ?>"/>
+    <input type="hidden" id="document-value" value="<?php echo $query['value']; ?>"/>
+
+    <script>
+    $(function() {
+        initializeEdit('<?php echo $GLOBALS["conf"]["api_endpoint"] ?>');
+    });
+    </script>
+
+</body>
+
+</html>

+ 26 - 33
arav_up_client/scripts/arkiwi.js

@@ -24,46 +24,19 @@ ARKIWI.Uploader = function (uploaderUrl, defaultParameters, formName, sessionUpl
 ARKIWI.Uploader.constructor = ARKIWI.Uploader;
 
 /* Invia un file all'uploader. */
-//ARKIWI.Uploader.prototype.upload = function (form, destinationFolderBase64, callbacks) {
-//    form = $(form);
-//
-//    form.attr('method', 'POST');
-//    form.attr('action', this.uploaderUrl + '/upload/' + this.sessionId + '/' + destinationFolderBase64 + '/?' + this.defaultParameters);
-//    form.attr('id', this.formName);
-//    form.attr('enctype', 'multipart/form-data');
-//    form.attr('target', 'arkiwi_hidden_iframe');
-//
-//    form.append('<input type="hidden" value="' + this.formName + '" name="' + this.sessionUploadProgressName + '" />');
-//
-//    $(':file', form).attr('name', this.sessionId);
-//
-//    form.ajaxForm({
-//        beforeSend: function () {
-//            callbacks.beforeSend();
-//        },
-//        uploadProgress: function (event, position, total, percentComplete) {
-//            callbacks.uploadProgress(event, position, total, percentComplete);
-//        },
-//        complete: function (xhr) {
-//            callbacks.complete(xhr);
-//        },
-//        error: function (xhr, status, error) {
-//            throw 'Arkiwi.upload(): error ' + error;
-//        }
-//    });
-//
-//    form.submit();
-//};
-
 ARKIWI.Uploader.prototype.upload = function (file, destinationFolderBase64, callbacks) {
     var xhr = new XMLHttpRequest();
     xhr.withCredentials = true;
 
     var self = this;
 
-    xhr.upload.addEventListener("progress", function(e) {}, false);
+    xhr.upload.addEventListener("progress", function(e) {
+        callbacks.progress(e);
+    }, false);
 
-    xhr.upload.addEventListener("load", function(e){}, false);
+    xhr.upload.addEventListener("load", function(e){
+        callbacks.load(e);
+    }, false);
 
     xhr.open("POST", this.uploaderUrl + '/upload/' + destinationFolderBase64 + '/?' + this.defaultParameters, true);
 
@@ -75,6 +48,26 @@ ARKIWI.Uploader.prototype.upload = function (file, destinationFolderBase64, call
     xhr.send(fileData);
 };
 
+/* Aggiunge o sovrascrive i metadati di un file. */
+ARKIWI.Uploader.prototype.listMetadata = function (item64, callback) {
+    $.ajax({
+        url: this.uploaderUrl + '/listmetadata/' + item64 + '/?' + this.defaultParameters,
+        type: 'GET',
+        async: true,
+        cache: false,
+        context: this,
+        data: '',
+        dataType: 'json',
+        error: function (xhr, status, error) {
+            throw 'Arkiwi.listMetadata(): status ' + status + ' error ' + error;
+        },
+        success: function (result, status, xhr) {
+            if (callback != undefined)
+                callback(result);
+        },
+        complete: function (xhr, status) {}
+    });
+};
 
 /* Aggiunge o sovrascrive i metadati di un file. */
 ARKIWI.Uploader.prototype.metadata = function (jsonKVString, callback) {

+ 16 - 1
arav_up_client/scripts/main.js

@@ -15,6 +15,7 @@
 var arkiwi;
 var documentType;
 var documentValue;
+var originalMetadata;
 
 function supportAjaxUploadWithProgress() {
     return supportFileAPI() && supportAjaxUploadProgressEvents();
@@ -31,7 +32,7 @@ function supportAjaxUploadWithProgress() {
     };
 }
 
-function initialize(endpoint) {
+function initializeUpload(endpoint) {
     if (!supportAjaxUploadWithProgress()) {
         var body = $('body');
         body.empty();
@@ -49,6 +50,20 @@ function initialize(endpoint) {
 
 };
 
+function initializeEdit(endpoint) {
+    arkiwi = new ARKIWI.Uploader(endpoint);
+    documentType = $('#document-type').val();
+    documentValue = $('#document-value').val();
+
+    arkiwi.listMetadata(documentValue, function(result){
+        originalMetadata = JSON.parse(result);
+        var metadataContainer = $('#metadata_container');
+        for (var i=0; i < originalMetadata[0][1].length; i++) {
+            metadataContainer.append('<div><span>' + originalMetadata[0][1][i][0] + '</span><intput value="' + originalMetadata[0][1][i][1] + '"/></div>');
+        }
+    })
+}
+
 function selectFile(e) {
     $('input[id=hiddenfileinput]').click();
     e.preventDefault();

+ 1 - 5
arav_up_client/upload.php

@@ -26,10 +26,6 @@
     //     report(1,"esito not AUTH_OK, exiting");
         exit;
     }
-    else {
-        // registra in sessione i dati dell'utente //FIXME lo facciamo qui o dentro la funzione do_local_auth?
-        $_SESSION['authstate'] = $authstate;  //FIXME questo NON serve a niente
-    }
 
     // -----------------
 
@@ -73,7 +69,7 @@
 
     <script>
     $(function() {
-        initialize('<?php echo $GLOBALS["conf"]["api_endpoint"] ?>');
+        initializeUpload('<?php echo $GLOBALS["conf"]["api_endpoint"] ?>');
     });
     </script>
 

+ 6 - 2
arav_up_confs.php

@@ -50,9 +50,13 @@ $GLOBALS["conf"]["dirmetadatafile"] = "dir.data";
 
 $GLOBALS["conf"]["user_db"] = "/home/cek/git/arkiwiapi/arav_up_users/arav_users.sqlite3";
 
-$GLOBALS["conf"]["data_basedir"] = "/var/www/vhosts/arav.ventuordici.org/htdocs/"; // dove stanno i doc fisici
-$GLOBALS["conf"]["metadata_basedir"] = "/var/www/vhosts/backend.arkiwi.org/htdocs/"; // dove stanno i metadati derivati
+$GLOBALS["conf"]["data_basedir"] = "/tmp"; // dove stanno i doc fisici
+$GLOBALS["conf"]["metadata_basedir"] = "/tmp"; // dove stanno i metadati derivati
 
 //campi di configurazione per il client html
 $GLOBALS["conf"]["api_endpoint"] = "http://arkiwi_up/arav_up_api";
+
+//campi di configurazione per la parte "CAZZACCROCCHIO"
+$GLOBALS["conf"]["assetstore_endpoint"] = "http://assetstore.arkiwi.org";
+
 ?>