Commit 30207a78 authored by Jerome Chauveau's avatar Jerome Chauveau
Browse files

un peu de nettoyage du plugin eadseach

parent 654fc2da
Loading
Loading
Loading
Loading
+180 −215
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ import {Plugin} from '../../core/ui/js/Plugin.js';
const PAGE_LENGTH = 10;

class EadSearchPlugin extends Plugin {

    constructor(name) {
        super(name);
        this.currentFirstLetterFilter = null;
@@ -14,16 +15,13 @@ class EadSearchPlugin extends Plugin{
                if (!this.withDatesFilter) {
                    document.getElementById('ead-search-date-from').setAttribute('disabled', true);
                    document.getElementById('ead-search-date-to').setAttribute('disabled', true);
            }
            else{
                } else {
                    document.getElementById('ead-search-date-from').removeAttribute('disabled');
                    document.getElementById('ead-search-date-to').removeAttribute('disabled')
                }
            })
            this.bindIndexAutocompletes();
        }
//        this.fetchIndexLists();

    }

    bindIndexAutocompletes() {
@@ -65,8 +63,7 @@ class EadSearchPlugin extends Plugin{
        let popupElt = document.getElementById('ead-search-popup-' + tagId);
        if (popupElt.style.display == 'block') {
            popupElt.style.display = 'none';
    }
    else
        } else
            this.popupIndex(tagId);
    }

@@ -128,38 +125,12 @@ class EadSearchPlugin extends Plugin{
                popupContent.appendChild(this.buildPager(tagId, total));
        })
    }
//
//  fetchIndexLists(){
//    let indexList = document.querySelectorAll('.ead-search-input')
//
//    indexList.forEach((e) => {
//        let indexName = e.dataset.index;
//        fetch(baseURI + projectId + '/search-index/'+indexName+'.json').then((res) => res.json()).then( (json) => {
//                let datalist = document.getElementById(indexName);
//                let entries = json.entries
//                entries.forEach((entry) => {
//                    let option = document.createElement('option');
//                    option.value = decodeURIComponent(entry.normal);
//                    datalist.appendChild(option);
//
//                })
//
//                document.getElementById(indexName+'-input').addEventListener('input', (event) => {
//                        //alert(event.target.value)
//                        if(event.inputType === 'insertReplacementText'){
//                            this.addIndexFilter(indexName, event.target.value)
//                        }
//
//                });
//            })
//
//
//    })
//  }

    fetchIndexEntriesByLetter(letter, tagId) {
        this.currentFirstLetterFilter = letter.trim() === '' ? null : letter;
    document.querySelectorAll('.ead-search-alpha.selected').forEach(e => {e.classList.toggle('selected')})
        document.querySelectorAll('.ead-search-alpha.selected').forEach(e => {
            e.classList.toggle('selected')
        })
        document.getElementById("alpha-" + tagId + (this.currentFirstLetterFilter ? '-' + this.currentFirstLetterFilter : '')).classList.toggle('selected')
        this.fetchPage(tagId, 1)
    }
@@ -183,7 +154,6 @@ class EadSearchPlugin extends Plugin{
            this.filters[filterType].splice(this.filters[filterType].indexOf(filterValue), 1);
            if (this.filters[filterType].length === 0)
                delete this.filters[filterType];
        console.log(this.filters);
        })
    }

@@ -235,9 +205,7 @@ class EadSearchPlugin extends Plugin{
    runEadSearch() {
        //pour ne pas que les résultats précédents restent affichés, on vide le contenu html
        let resultsDiv = document.querySelector("#ead-search-results");
	while (resultsDiv.firstChild) {
		resultsDiv.removeChild(resultsDiv.firstChild);
	}
        resultsDiv.innerHTML = '';
        let query = 'resultats.html';
        document.querySelector("#searchLoading").style.display = "block";
        let filtered = false;
@@ -260,8 +228,7 @@ class EadSearchPlugin extends Plugin{
                let to = document.getElementById('ead-search-date-to').value;
                if (from && to)
                    query += (!filtered ? "?" : "&") + "from=" + from + "&to=" + to
            }
            else if (dateMode === 'in'){
            } else if (dateMode === 'in') {
                let dateIn = document.getElementById('ead-search-date-in').value;
                query += (!filtered ? "?" : "&") + "in=" + dateIn
            }
@@ -278,9 +245,7 @@ class EadSearchPlugin extends Plugin{
        var simpleSearch = document.querySelector('#searchInput').value;
        //pour ne pas que les résultats précédents restent affichés, on vide le contenu html
        let resultsDiv = document.querySelector("#ead-search-results");
	while (resultsDiv.firstChild) {
		resultsDiv.removeChild(resultsDiv.firstChild);
	}
        resultsDiv.innerHTML = '';
        if (simpleSearch.trim() === '') {
            alert('Recherche vide ou incorrecte.');
            return;
+0 −61
Original line number Diff line number Diff line
@@ -310,16 +310,6 @@ function max.plugin.ead_search:searchIndexesListAsJSON($project, $tag, $page as



(:declare %private function max.plugin.ead_search:indexFirstLetters($project, $tag as xs:string, $attr as xs:string, $value as xs:string){:)
(: $page = -1 means all entries :)
(:let $entries := max.plugin.ead_search:searchIndexesList($project, $tag, -1, $attr, $value, ()):)
(:let $letters := for $entry in distinct-values($entries//@normal) return substring($entry,1,1):)
(:return distinct-values($letters):)

(:};:)



declare
%rest:GET
%rest:query-param("attr", "{$attr}")
@@ -371,23 +361,6 @@ function max.plugin.ead_search:searchIndexesList($project, $tag, $page as xs:int
};


(:
declare %private function max.plugin.ead_search:countTagsWithFirstLetter($project, $tagName, $letter){
    let $dbPath := max.config:getProjectDBPath($project)
    let $tagParameters := max.plugin.ead_search:getSearchConfiguration($project)//tag[@name=$tagName]
    let $nodes := for $elt in collection($dbPath)//*[fn:local-name()=$tagName and @normal]
        where(
            if($tagParameters/@attribute) then
                $elt/@*[local-name(.)=string($tagParameters/@attribute) and string(.)=string($tagParameters/@value)]
            else true()
        )
        and(
            starts-with($elt/@normal, $letter)
        )
        return $elt
    return count($nodes)
};
:)

(:----------------------------test index-------------------------------------------:)

@@ -399,12 +372,6 @@ function max.plugin.ead_search:allLevels($project){
    let $doc := collection(max.config:getProjectDBPath($project))
    let $topLevels := for $i in distinct-values($doc//*:controlaccess[not(ancestor::*:controlaccess)]/descendant::*:subject[1]) order by $i
    return normalize-space($i)
        (:let $trimed := normalize-space($i)
        return
            if ($doc//*:controlaccess/*:controlaccess//*:controlaccess/*:subject[text() contains text {$trimed}])
        then ()
        else $trimed:)

    return
        <root>{
            for $top in $topLevels
@@ -548,31 +515,3 @@ Clés d'indexation en Pleade
|:--------------------------|:----------|:---------------------|:---------------------------|

:)


(:
https://redmine.unicaen.fr/Etablissement/boards/70/topics/200
:)

(:

declare
%rest:GET
%rest:path("/{$projectId}/{$xmlDocName}/famname/unique.xml")
function max.plugin.json_idx:famname($projectId, $xmlDocName){
let $dbPath := max.config:getProjectDBPath($projectId)
let $content := for $n in sort(distinct-values(doc(concat($dbPath, '/', $xmlDocName))//*:famname))
return <item>{$n}</item>
return <items>{$content}</items>
};
declare
%rest:GET
%rest:path("/{$projectId}/{$xmlDocName}/corpname/unique.xml")
function max.plugin.json_idx:corpname($projectId, $xmlDocName){
let $dbPath := max.config:getProjectDBPath($projectId)
let $content := for $n in sort(distinct-values(doc(concat($dbPath, '/', $xmlDocName))//*:corpname))
return <item>{$n}</item>
return <items>{$content}</items>
};

:)

plugins/ead_search/listeOld.png

deleted100644 → 0
−10.1 KiB
Loading image diff...
+0 −24
Original line number Diff line number Diff line
<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
  <xsl:output method="xml" omit-xml-declaration="yes" />
  <!-- <xsl:strip-space elements="tei:p tei:mod tei:add tei:persName"/> -->



	<xsl:template match="@*|node()">
@@ -9,27 +7,5 @@
			<xsl:apply-templates select="@*|node()"/>
		</xsl:copy>
	</xsl:template>
<!-- 
	<xsl:template match="*:div[@class='wrapResults']">
		<xsl:variable name="nbResults" select="count(.//*:div[@class='hit'])" />
		<xsl:copy>
			<div class="n-search-result"><xsl:value-of select="$nbResults||' résultat'"/><xsl:if test="$nbResults gt 1"><xsl:text>s</xsl:text></xsl:if></div>
			<xsl:apply-templates />
		</xsl:copy>
	</xsl:template>
	
	<xsl:template match="*:div[@class='hits']">
		<xsl:variable name="nbResults" select="count(.//*:div[@class='hit'])" />
		<xsl:if test="$nbResults!=0">
			<xsl:copy>
				<details class="blocResults" open="">
				<summary>
					<xsl:value-of select=".//*:h3||' ['||$nbResults||' résultat'||(if($nbResults gt 1) then('s') else())||']'"/>
					</summary>
					<xsl:apply-templates select=".//*:div[@class='hit']"/>
				</details>
			</xsl:copy>
		</xsl:if>
	</xsl:template>	 -->

</xsl:stylesheet>