Changeset 279


Ignore:
Timestamp:
04/15/10 17:52:44 (15 years ago)
Author:
lgiessmann
Message:

docs: fixed some bad ebnf definitions of the json interface; json: currently only active topics are exported, mark-as-deleted topics are not exported; ajax: added the possibility that the ui is able to mark topics, names and occurrences as deleted ---> at the moment there is a problem when recreating occurrences and names that have already existed

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/docs/json.ebnf

    r278 r279  
    195195DeleteTopics = "\"topics\":" List
    196196DeleteAssociations = "\"associations\":" Associations
    197 DeleteParentTopic = "\"parent-topic\":" String
    198 DeleteParentName = "\"parent-name\":" Name
     197DeleteParentTopic = "\"parentTopic\":" String
     198DeleteParentName = "\"parentName\":" Name
    199199DeleteNames = "\"names\":" Names
    200200DeleteVariants = "\"variants\":" Variants
    201201DeleteOccurrences = "\"occurrences\":" Occurrences
    202 DeleteParentAssociation = "\"parent-association\":" Association
     202DeleteParentAssociation = "\"parentAssociation\":" Association
    203203DeleteRoles = "\"roles\":" Roles
    204204
  • TabularUnified trunk/docs/xtm_json.txt

    r278 r279  
    468468  "topics": [<psi-top-1>, <psi-top-2>, <...>],
    469469  "associations": [<association-1>, <association-2>, <...>],
    470   "parent-topic": "topic-psi",
    471   "parent-name": <name>,
     470  "parentTopic": "topic-psi",
     471  "parentName": <name>,
    472472  "names": [<name-1>, <name-2>, <...>],
    473473  "variants": [<variant-1>, <variant-2>, <...>],
    474474  "occurrences": [<occurrence-1>, <occurrence-2>, <...>],
    475   "parent-association": <association>,
     475  "parentAssociation": <association>,
    476476  "roles": [<role-1>, <role-2>, <...>]
    477477}
  • TabularUnified trunk/src/ajax/css/frame.css

    r75 r279  
    2828}
    2929
     30tr.removeNameRow {
     31    background-color: #eaeaee;
     32}
     33
     34tr.removeOccurrenceRow {
     35    background-color: #eaeaee;
     36}
     37
     38tr.removeTopicRow {
     39    background-color: #eaeaee;
     40}
     41
    3042li.errorMessage {
    3143    margin-top: 1em;
     
    140152}
    141153
     154span.removeLink {
     155    cursor: pointer;
     156    font-size: 0.75em;
     157    float: right;
     158    margin-right: 1em;
     159}
     160
     161span.removeLink:hover {
     162    color:#ff7f00;
     163}
     164
    142165
    143166/* === topic frame ========================================================== */
  • TabularUnified trunk/src/ajax/javascripts/constants.js

    r275 r279  
    2323var OWN_URL = HOST_PREF + "isidorus";
    2424var SUMMARY_URL = HOST_PREF + "json/summary"
     25    var MARK_AS_DELETED_URL = HOST_PREF + "mark-as-deleted";
    2526var TM_OVERVIEW = "/json/tmcl/overview/";
    2627var TIMEOUT = 10000; // const TIMEOUT = 10000 --> "const" doesn't work under IE
     
    9091               "instances" : function(){ return "instances"; },
    9192               "subtypes" : function(){ return "subtypes"; },
    92                "topicPsis" : function(){ return "topicPsis"; }
     93               "topicPsis" : function(){ return "topicPsis"; },
     94               "removeLink" : function(){ return "removeLink"; },
     95               "removeNameRow" : function(){ return "removeOccurrenceRow"; },
     96               "removeOccurrenceRow" : function(){ return "removeNameRow"; },
     97               "removeTopicRow" : function(){ return "removeTopicRow"; }
    9398              };
  • TabularUnified trunk/src/ajax/javascripts/datamodel.js

    r179 r279  
    14481448                                                      });
    14491449                                              }
     1450
     1451                                              var myself = this;
     1452                                              this.__table__.insert({"bottom" : makeRemoveLink(function(event){
     1453                                                              makeDeleteObject("Name", myself);
     1454                                                          }, "delete Name")});
    14501455                                          }
    14511456                                          catch(err){
     
    14921497                                              this.getFrame().select("tr." + CLASSES.valueFrame())[0].hide();
    14931498                                              this.getFrame().select("tr." + CLASSES.variantContainer())[0].hide();
     1499                                              this.getFrame().select("tr." + CLASSES.removeNameRow())[0].hide();
    14941500                                              this.__isMinimized__ = true;
    14951501                                          }
     
    15011507                                              this.getFrame().select("tr." + CLASSES.valueFrame())[0].show();
    15021508                                              this.getFrame().select("tr." + CLASSES.variantContainer())[0].show();
     1509                                              this.getFrame().select("tr." + CLASSES.removeNameRow())[0].show();
    15031510                                              this.__isMinimized__ = false;
    15041511                                          }
     
    15131520                                          this.getFrame().writeAttribute({"class" : CLASSES.disabled()});
    15141521                                          this.getFrame().writeAttribute({"title" : this.__cssTitle__});
     1522                                          this.getFrame().select("tr." + CLASSES.removeNameRow())[0].disable();
    15151523                                          this.hideAddButton();
    15161524                                          this.__disabled__ = true;
     
    15241532                                          this.getFrame().writeAttribute({"class" : CLASSES.nameFrame()});
    15251533                                          this.getFrame().removeAttribute("title");
     1534                                          this.getFrame().select("tr." + CLASSES.removeNameRow())[0].enable();
    15261535                                          checkRemoveAddButtons(this.__owner__, 1, this.__max__, this);
    15271536                                          this.__disabled__ = false;
     
    17431752
    17441753
     1754function makeRemoveLink (removeHandler, textContent){
     1755    var link = new Element("span", {"class" : CLASSES.removeLink()}).update(textContent);
     1756    var trClass = null;
     1757    switch(textContent){
     1758      case "delete Occurrence" : trClass = CLASSES.removeOccurrenceRow(); break;
     1759      case "delete Topic" : trClass = CLASSES.removeTopicRow(); break;
     1760      case "delete Name" : trClass = CLASSES.removeNameRow(); break;
     1761    }
     1762
     1763    var tr = new Element("tr", {"class" : trClass}).insert(new Element("td", {"colspan" : 3}).insert(link));
     1764    if(removeHandler){ link.observe("click", removeHandler); }
     1765    return tr;
     1766}
     1767
     1768
     1769function makeDeleteObject(type, objectToDelete){
     1770    if(type !== "Occurrence" && type !== "Name" && type !== "Variant"
     1771       && type !== "Topic" && type !== "Association"){
     1772        throw "From makeDeleteObject(): type must be: \"Occurrence\" || \"Name\" " +
     1773            "|| \"Variant\" || \"Topic\" || \"Association\" but is " + type;
     1774    }
     1775    if (!objectToDelete){
     1776        throw "From makeDeleteObject(): objectToDelete must be set";
     1777    }
     1778
     1779    var parentTopic = "null";
     1780    if(type === "Occurrence" || type === "Name"){
     1781        var psiFrame = objectToDelete.getFrame().parentNode.parentNode.parentNode.parentNode.select("tr." + CLASSES.subjectIdentifierFrame())[0];
     1782        var psiFields = psiFrame.select("input");
     1783        for(i = 0; psiFields && i !== psiFields.length; ++i){
     1784            var psiValue = psiFields[i].value;
     1785            if(psiValue.strip().length !== 0){
     1786                parentTopic = psiValue.strip().toJSON();
     1787                break;
     1788            }
     1789        }
     1790    }
     1791
     1792    var topics = "null";
     1793    if (type === "Topic"){
     1794        var psiFrame = objectToDelete.getFrame().select("tr." + CLASSES.subjectIdentifierFrame())[0];
     1795        var psiFields = psiFrame.select("input");
     1796        for(i = 0; psiFields && i !== psiFields.length; ++i){
     1797            var psiValue = psiFields[i].value;
     1798            if(psiValue.strip().length !== 0){
     1799                topics = new Array(psiValue.strip()).toJSON();
     1800                break;
     1801            }
     1802        }
     1803    }
     1804
     1805    var deletedObjects = null;
     1806    if(type === "Topic"){ deletedObjects = topics; }
     1807    else { deletedObjects = "[" + objectToDelete.toJSON() + "]"; }
     1808
     1809    var jsonData = "{\"type\":\"" + type + "\"," +
     1810                    "\"topics\":" + topics + "," +
     1811                    "\"associations\":" + "null" + "," +
     1812                    "\"parentTopic\":" + parentTopic + "," +
     1813                    "\"parentName\":" + "null" + "," +
     1814                    "\"names\":" + (type === "Name" ? deletedObjects : "null") + "," +
     1815                    "\"variants\":" + "null" + "," +
     1816                    "\"occurrences\":" + (type === "Occurrence" ? deletedObjects : "null") + "," +
     1817                    "\"parentAssociation\":" + "null" + "," +
     1818                    "\"roles\":" + "null" + "}";
     1819 
     1820    commitDeletedObject(jsonData, function(xhr){
     1821            alert("Objected deleted");
     1822            if(type === "Topic"){
     1823                $(CLASSES.subPage()).update();
     1824                makeHome();
     1825            }
     1826            else if (type === "Occurrence" || type === "Name"){
     1827                if(objectToDelete.__owner__.__frames__.length > objectToDelete.__max__
     1828                   && objectToDelete.__owner__.__frames__.length > 1){
     1829                    objectToDelete.remove();
     1830                }
     1831                else {
     1832                    if(type === "Occurrence"){ objectToDelete.__value__.setValue(""); }
     1833                    else { objectToDelete.__value__.__frames__[0].__content__.setValue(""); }
     1834                }
     1835            }
     1836        });
     1837   
     1838}
     1839
    17451840// --- represenation of an occurrence element
    17461841var OccurrenceC = Class.create(ContainerC, {"initialize" : function($super, contents, occurrenceTypes, constraint, uniqueConstraints, owner, min, max, cssTitle, dblClickHandler){
     
    18271922                                                            });
    18281923                                                    }
     1924                                                    var myself = this;
     1925                                                    this.__table__.insert({"bottom" : makeRemoveLink(function(event){
     1926                                                                    makeDeleteObject("Occurrence", myself);
     1927                                                                }, "delete Occurrence")});
    18291928                                                }
    18301929                                                catch(err){
     
    18951994                                                    this.getFrame().select("tr." + CLASSES.valueFrame())[0].hide();
    18961995                                                    this.getFrame().select("tr." + CLASSES.datatypeFrame())[0].hide();
     1996                                                    this.getFrame().select("tr." + CLASSES.removeOccurrenceRow())[0].hide();
    18971997                                                    this.__isMinimized__ = true;
    18981998                                                }
     
    19042004                                                    this.getFrame().select("tr." + CLASSES.valueFrame())[0].show();
    19052005                                                    this.getFrame().select("tr." + CLASSES.datatypeFrame())[0].show();
     2006                                                    if(this.__disabled__ === false){
     2007                                                        this.getFrame().select("tr." + CLASSES.removeOccurrenceRow())[0].show();
     2008                                                    }
    19062009                                                    this.__isMinimized__ = false;
    19072010                                                }
     
    19172020                                                this.getFrame().writeAttribute({"title" : this.__cssTitle__});
    19182021                                                this.hideAddButton();
     2022                                                this.getFrame().select("tr." + CLASSES.removeOccurrenceRow())[0].hide();
    19192023                                                this.__disabled__ = true;
    19202024                                            },
     
    19292033                                                this.getFrame().removeAttribute("title");
    19302034                                                checkRemoveAddButtons(this.__owner__, 1, this.__max__, this);
     2035                                                this.getFrame().select("tr." + CLASSES.removeOccurrenceRow())[0].show();
    19312036                                                this.__disabled__ = false;
    19322037                                            }});
     
    22232328                                               this.__occurrence__ = new OccurrenceContainerC(occurrencesContent, _constraints);
    22242329                                               this.__table__.insert({"bottom" : newRow(CLASSES.occurrenceContainer(), "Occurrences", this.__occurrence__.getFrame())});
     2330
     2331                                               var myself = this;
     2332                                               this.__table__.insert({"bottom" : makeRemoveLink(function(event){
     2333                                                               makeDeleteObject("Topic", myself);
     2334                                                           }, "delete Topic")});
    22252335                                           }catch(err){
    22262336                                               alert("From TopciC(): " + err);
     
    22622372                                                     this.getFrame().select("tr." + CLASSES.subjectIdentifierFrame())[0],
    22632373                                                     this.getFrame().select("tr." + CLASSES.nameContainer())[0],
    2264                                                      this.getFrame().select("tr." + CLASSES.occurrenceContainer())[0]);
     2374                                                     this.getFrame().select("tr." + CLASSES.occurrenceContainer())[0],
     2375                                                     this.getFrame().select("tr." + CLASSES.removeTopicRow())[0]);
    22652376                                           for(var i = 0; i != rows.length; ++i){
    22662377                                               if(this.__minimized__ === false) rows[i].hide();
  • TabularUnified trunk/src/ajax/javascripts/requests.js

    r84 r279  
    220220
    221221
     222// --- Sends a POST-Message to the server. The sent message enables the server
     223// --- to find the spcified object and mark it as deleted
     224function commitDeletedObject(json, onSuccessHandler, onFailureHandler)
     225{
     226    if(!json || !onSuccessHandler) throw "From commitDeletedObject(): json and onSuccessHandler must be set!";
     227    try{
     228        var onFailure = onFailureHandler ? onFailureHandler : defaultFailureHandler;
     229        var timeFun = setAjaxTimeout(TIMEOUT, COMMIT_URL);
     230       
     231        new Ajax.Request(MARK_AS_DELETED_URL, {
     232            "method" : "post",
     233            "postBody" : json,
     234            "onSuccess" : createXHRHandler(onSuccessHandler, timeFun),
     235            "onFailure" : createXHRHandler(onFailure, timeFun)});
     236    }
     237    catch(err){
     238        alert("From commitDeletedObject(): " + err);
     239    }
     240}
     241
     242
    222243// --- Requests a JSON-Fragment for the passed psi and calls the onSuccessHandler function
    223244// --- after a succeeded request.
  • TabularUnified trunk/src/json/json_exporter.lisp

    r27 r279  
    99
    1010(defpackage :json-exporter
    11   (:use :cl :json :datamodel)
     11  (:use :cl :json :datamodel :json-tmcl-constants)
    1212  (:export :to-json-string
    1313           :get-all-topic-psis
     
    299299                                    (when psi-list
    300300                                      (map 'list #'uri psi-list)))
    301                           (map 'list #'psis (elephant:get-instances-by-class 'TopicC))))))
     301                          (json-tmcl::clean-topics
     302                           (elephant:get-instances-by-class 'TopicC))))))
    302303
    303304
     
    352353        (concatenate 'string "[" json-string "]"))
    353354      "null"))
     355
     356
     357(defun clean-topics(isas-or-akos)
     358  (remove-if
     359   #'null
     360   (map 'list
     361        #'(lambda(top)
     362            (when (d:find-item-by-revision top 0)
     363              top))
     364        isas-or-akos)))
  • TabularUnified trunk/src/json/json_importer.lisp

    r229 r279  
    363363              (t
    364364               (error "json-importer:get-fragment-values-from-json-string:
    365                        bad item-specifier found in json-list"))))
     365                       bad item-specifier found in json-list (~a)" (car j-elem)))))
    366366      (unless topic
    367367        (error "json-importer:get-fragment-values-from-json-string: the element topic must be set"))
  • TabularUnified trunk/src/json/json_tmcl.lisp

    r277 r279  
    180180  (declare (list names) (string parent-psi) (integer revision))
    181181  (let ((parent-topic (d:get-item-by-psi parent-psi))
    182         (err "From delete-name-from-json(): "))
     182        (err "From delete-names-from-json(): "))
    183183    (unless parent-topic
    184184      (error "~a~a not found"
     
    236236  (declare (list occurrences) (string parent-psi) (integer revision))
    237237  (let ((parent-topic (d:get-item-by-psi parent-psi))
    238         (err "From delete-occurrence-from-json(): "))
     238        (err "From delete-occurrences-from-json(): "))
    239239    (unless parent-topic
    240240      (error "~a~a not found" err parent-psi))
     
    285285  (dolist (j-assoc associations)
    286286    (let ((plist (json-importer::get-association-values-from-json-list j-assoc))
    287           (err "From delete-association-from-json(): "))
     287          (err "From delete-associations-from-json(): "))
    288288      (let ((assoc (find-association-from-json plist)))
    289289        (unless assoc
     
    298298      (let ((psi (elephant:get-instance-by-value 'd:PersistentIdC 'd:uri uri)))
    299299        (unless psi
    300           (error "From delete-topic-from-json(): PSI ~a not found" uri))
     300          (error "From delete-topics-from-json(): PSI ~a not found" uri))
    301301        (pushnew psi psis)))
    302302    (let ((tops
     
    15741574                                       (get-direct-subtypes-of-topic topic-instance)))))))
    15751575      (let ((cleaned-isas ;;all constraint topics are removed
    1576              (remove-if #'null (map 'list #'(lambda(top-entry)
    1577                                               (when (find-if #'(lambda(psi)
    1578                                                                    (unless (or (string= (uri psi) *constraint-psi*)
    1579                                                                                (string= (uri psi) *occurrencetype-psi*)
    1580                                                                                (string= (uri psi) *nametype-psi*)
    1581                                                                                (string= (uri psi) *associationtype-psi*)
    1582                                                                                (string= (uri psi) *roletype-psi*)
    1583                                                                                (string= (uri psi) *scopetype-psi*)
    1584                                                                                (string= (uri psi) *schema-psi*))
    1585                                                                      top-entry))
    1586                                                                (psis (getf top-entry :topic)))
    1587                                                 top-entry))
    1588                                     isas-of-this)))
     1576             (clean-topic-entries isas-of-this))
    15891577            (cleaned-akos ;;all constraint topics are removed
    1590              (remove-if #'null (map 'list #'(lambda(top-entry)
    1591                                               (when (find-if #'(lambda(psi)
    1592                                                                    (unless (or (string= (uri psi) *constraint-psi*)
    1593                                                                                (string= (uri psi) *occurrencetype-psi*)
    1594                                                                                (string= (uri psi) *nametype-psi*)
    1595                                                                                (string= (uri psi) *associationtype-psi*)
    1596                                                                                (string= (uri psi) *roletype-psi*)
    1597                                                                                (string= (uri psi) *scopetype-psi*)
    1598                                                                                (string= (uri psi) *schema-psi*))
    1599                                                                      top-entry))
    1600                                                                (psis (getf top-entry :topic)))
    1601                                                 top-entry))
    1602                                     akos-of-this))))
     1578             (clean-topic-entries akos-of-this)))
    16031579        (list :topic topic-instance
    16041580              :is-type is-type
     
    16111587                             cleaned-akos))))))
    16121588
     1589(defun clean-topic-entries(isas-or-akos)
     1590  (remove-if
     1591   #'null
     1592   (map 'list
     1593        #'(lambda(top-entry)
     1594            (when (and (d:find-item-by-revision (getf top-entry :topic) 0)
     1595                       (find-if
     1596                        #'(lambda(psi)
     1597                            (unless (or (string= (uri psi) *constraint-psi*)
     1598                                        (string= (uri psi) *occurrencetype-psi*)
     1599                                        (string= (uri psi) *nametype-psi*)
     1600                                        (string= (uri psi) *associationtype-psi*)
     1601                                        (string= (uri psi) *roletype-psi*)
     1602                                        (string= (uri psi) *scopetype-psi*)
     1603                                        (string= (uri psi) *schema-psi*))
     1604                              top-entry))
     1605                        (psis (getf top-entry :topic))))
     1606              top-entry))
     1607        isas-or-akos)))
     1608
    16131609
    16141610(defun get-all-tree-roots ()
     
    16161612   of any other topic."
    16171613  (let ((all-topics
    1618          (elephant:get-instances-by-class 'd:TopicC)))
     1614         (remove-if #'null
     1615                    (map 'list
     1616                         #'(lambda(top)
     1617                             (when (d:find-item-by-revision top 0)
     1618                               top))
     1619                         (elephant:get-instances-by-class 'd:TopicC)))))
    16191620    (remove-if #'null
    16201621               (map 'list #'(lambda(x)
  • TabularUnified trunk/src/json/json_tmcl_validation.lisp

    r85 r279  
    376376  "Returns all topics that are valid tmcl-types"
    377377  (let ((all-topics
    378          (elephant:get-instances-by-class 'd:TopicC))
     378         (json-exporter::clean-topics
     379          (elephant:get-instances-by-class 'd:TopicC)))
    379380        (topictype (get-item-by-psi json-tmcl-constants::*topictype-psi*))
    380381        (topictype-constraint (is-type-constrained)))
     
    400401   type-instance or supertype-subtype."
    401402  (let ((all-topics
    402          (elephant:get-instances-by-class 'd:TopicC)))
     403         (json-exporter::clean-topics
     404          (elephant:get-instances-by-class 'd:TopicC))))
    403405    (let ((valid-instances
    404406           (remove-if #'null
  • TabularUnified trunk/src/rest_interface/set-up-json-interface.lisp

    r275 r279  
    116116   hunchentoot:*dispatch-table*)
    117117  (push
    118    (create-regex-dispatcher mark-as-deleted-url #'mark-as-deleted)
     118   (create-regex-dispatcher mark-as-deleted-url #'mark-as-deleted-handler)
    119119   hunchentoot:*dispatch-table*))
    120120
     
    303303    (handler-case (with-reader-lock
    304304                    (let ((topics
    305                            (elephant:get-instances-by-class 'd:TopicC)))
     305                           (remove-if
     306                            #'null
     307                            (map 'list #'(lambda(top)
     308                                           (when (d:find-item-by-revision top 0)
     309                                             top))
     310                                 (elephant:get-instances-by-class 'd:TopicC)))))
    306311                      (let ((end
    307312                             (cond
     
    373378        (setf (hunchentoot:return-code*) hunchentoot:+http-bad-request+))))
    374379
     380
    375381;; =============================================================================
    376382;; --- some helper functions ---------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.