rules.tag.html 6.5 KB
Newer Older
Yohan Boniface's avatar
Yohan Boniface committed
1
<rules>
2
  <div id="ref-main-div" class="bg-white">  
3 4
    <div id="ref-header-row">
      <div class="container">
Lucas Détré's avatar
Lucas Détré committed
5 6
        <div class="row mb-4">
          <div id="ref-count-financements" class="col-md-3 col-sm-6 col-xs-12">
7 8 9
            <span id="ref-count-financements-number" class="ref-results-count-number ref-count-financements-text">{ this.count_financements }</span>
            <span class="ref-count-financements-text" if={ this.lt_two }>&nbsp;financement</span>
            <span class="ref-count-financements-text" if={ !this.lt_two }>&nbsp;financements</span>
10
          </div>
Lucas Détré's avatar
Lucas Détré committed
11
          <div id="ref-create-financement" class="col-md-3 col-sm-6 col-xs-12 my-auto">
12 13
            <button href="#" class="btn btn-outline-success" disabled>Créer un financement</button>
          </div>
Lucas Détré's avatar
Lucas Détré committed
14 15
          <div id="ref-search-financement" class="col-md-6 col-sm-12 col-xs-12 my-auto">
            <div class="form-inline pull-right">
16
              <div class="form-group mx-sm-3 mb-2">
Lucas Détré's avatar
Lucas Détré committed
17
                <input class="form-control" id="financement-search-field" name="financement-search" type="search" placeholder="Rechercher">
18
              </div>
Lucas Détré's avatar
Lucas Détré committed
19
            </div>
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
          </div>
        </div>
        <div class="row">
          <div id="ref-last-update" class="col-md-12">
            Dernière mise à jour le <> à <>
          </div>
        </div>
      </div>
    </div>
    <hr class="ref-horizontal-separator">
    <div id="ref-filter-row" class="container">
      <label for="financement-filter-select">Filtrer par</label>
      <select id="financement-filter-select" class="form-control" name="financement-filter-select" disabled>
        <option>Tous les publics</option>
      </select>
    </div>
    <hr class="ref-horizontal-separator">
    <div id="ref-result-row" class="container">
      <span class="ref-results-count" if={ this.lt_two }>
39
          Résultat (<span class="ref-results-count-number">{ this.count_financements }</span>)
40 41
      </span>
      <span class="ref-results-count" if={ !this.lt_two }>
42
          Résultats (<span class="ref-results-count-number">{ this.count_financements }</span>)
43 44
      </span>
      <div id="ref-results-list">
45 46
        <ul id="ul-ref-results-list" class="container">
          <li each={ this.financements } class="mt-4 row">
47
            <span class="col-md-3 col-sm-12">
48
              <strong class="ref-fields">{ intitule }</strong>
49 50
            </span>
            <span class="col-md-8 col-sm-11">
51
              <button each={ tag in _tags} class="ref-results-tags btn btn-outline-info" href="#" disabled>{ tag }</button>
52 53 54 55 56 57 58 59 60 61 62 63 64 65
            </span>
            <span class="col-md-1 col-sm-1 pull-right">              
              <button href="https://framagit.org/ybon/trefle/tree/master/trefle/config/financements.yml" target="_blank" class="text-dark btn btn-outline-light" disabled>
                <i class="icon" style="vertical-align: baseline;">edit</i>
              </button>
            </span>
          </li>          
          <hr class="ref-list-horizontal-separator">
        </ul>
      </div>

    </div>
  </div>

Yohan Boniface's avatar
Yohan Boniface committed
66
  <script>
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    this.financements = []
    this.count_financements = 0
    this.lt_two = false;

    this.on('mount', () => this.load())

    this.load = () => {
      request('../explore/financements')
      .then(data => {
        this.financements = data
        for (var i = 0; i < this.financements.length; i++) {
          // Riot sucks on `tags`…
          this.financements[i]['_tags'] = this.financements[i]['tags']
          this.count_financements++
        }
        if (this.count_financements<2) this.lt_two=true;
        this.update()
84
      })      
85
    }
86

Yohan Boniface's avatar
Yohan Boniface committed
87
    this.mixin(View)
88 89 90

    $(document).ready(function() {
      $("#ref-main-div").css("height","100%");
91 92
      $("#ref-main-div").css("min-height","100vh");
      $("#financement-search-field").focus().keyup(function(event){
93 94 95
        var search_field = $(this);
        var search_field_value = search_field.val();
        if(search_field_value== ''){
96 97 98 99 100
          $("#ul-ref-results-list li").show();
          $(".ref-results-count-number").empty().text($("#ul-ref-results-list li:visible").length);   
          return true;
        }
        var regexp = '\\b(.*)';
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
        for (var i in search_field_value){
            regexp += '('+search_field_value[i]+')';
        }
        regexp += '(.*)';
        $("#ul-ref-results-list li").show();
        $("#ul-ref-results-list li").each(function() {
          $(this).find(".ref-results-tags").each(function() {
            var item = $(this);
            var regexp_results = item.text().match(new RegExp(regexp,'i'));
            if(regexp_results){
              var matching_string = '';
              for(var i in regexp_results){
                if(i > 0){  
                  matching_string += regexp_results[i];
                }
              }
              item.parent().parent().show();
              return false;
            } else{
              item.parent().parent().hide();
            }
            $(".ref-results-count-number").empty().append($("#ul-ref-results-list li:visible").length); 
          })           
        });
      });
    })

    /*$(document).ready(function() {
      $("#ref-main-div").css("height","100%");
      $("#ref-main-div").css("min-height","100vh");
      $("#financement-search-field").focus().keyup(function(event){
        var search_field = $(this);
        var search_field_value = search_field.val();
        if(search_field_value== ''){
          $("#ul-ref-results-list li").show();
          $(".ref-results-count-number").empty().text($("#ul-ref-results-list li:visible").length);   
          return true;
        }
        var regexp = '\\b(.*)';
        for (var i in search_field_value){
            regexp += '('+search_field_value[i]+')';
142 143 144 145 146
        }
        regexp += '(.*)\\b';
        $("#ul-ref-results-list li").show();
        $("#ul-ref-results-list").find('li .ref-fields').each(function() {
          var item = $(this);
147
          var regexp_results = item.text().match(new RegExp(regexp,'i'));
148
          if(results){
149 150
            var matching_string = '';
            for(var i in regexp_results){
151
              if(i > 0){  
152
                matching_string += regexp_results[i];
153 154
              }
            }
155
            item.empty().append(matching_string)
156 157 158
          } else{
            item.parent().parent().hide();
          }
159
          $(".ref-results-count-number").empty().append($("#ul-ref-results-list li:visible").length);  
160 161
        }); 
      });
162
    })*/
163

Yohan Boniface's avatar
Yohan Boniface committed
164 165
  </script>

Yohan Boniface's avatar
Yohan Boniface committed
166 167
  <style scoped>
    h3 {
Yohan Boniface's avatar
Yohan Boniface committed
168 169 170 171 172 173
      font-variant: small-caps;
    }
  </style>

</rules>