Project

General

Profile

« Previous | Next » 

Revision 2ed89b85

Added by Andreas Kohlbecker about 3 years ago

ref #7599 derivate tree with collapsible items

View differences:

modules/cdm_dataportal/classes/DerivationTreeComposer.php
6 6
  private $root_unit_dtos;
7 7
  private $focused_unit_uuid = null;
8 8
  private $with_details = false;
9
  private $collapsible = false;
10

  
11
  /**
12
   * @return bool
13
   */
14
  public function isCollapsible() {
15
    return $this->collapsible;
16
  }
17

  
18
  /**
19
   * @param bool $collapsible
20
   */
21
  public function setCollapsible($collapsible) {
22
    $this->collapsible = $collapsible;
23
  }
9 24

  
10 25
  /**
11 26
   * @return bool
......
14 29
    return $this->with_details;
15 30
  }
16 31

  
32
  public function collapsibleItemClassAttribute($has_sub_derivatives) {
33
    return $this->isCollapsible() & $has_sub_derivatives === TRUE ? ' tree-item-collapsible' : '';
34

  
35
  }
36

  
37
  public function subItemsClassAttribute($has_sub_derivatives) {
38
    return $has_sub_derivatives === true ? ' with-sub-items' : '';
39
  }
40

  
41
  public function itemCollapsedStateClassAttribute() {
42
    return $this->isCollapsible() ? ' collapsed' : '';
43
  }
44

  
17 45
  /**
18 46
   * @param bool $with_details
19 47
   */
......
64 92
    $render_array = [];
65 93
    $render_array['derived-unit-tree'] = $derivation_tree;
66 94

  
67
    _add_js_derivation_tree('.derived-unit-tree');
95
    _add_js_derivation_tree('.item-tree');
68 96

  
69 97
    return $render_array;
70 98
  }
......
81 109
   *    An array which can be used in render arrays to be passed to the
82 110
   * theme_table() and theme_list().
83 111
   */
84
  private function derived_units_tree() {
85 112

  
113
  private function derived_units_tree() {
86 114
    RenderHints::pushToRenderStack('derived-unit-tree');
87 115
    RenderHints::setFootnoteListKey('derived-unit-tree');
88 116

  
89
    $root_items = [];
90
    //we need one more item to contain the items of one level (fieldunit, derivate data etc.)
91
    foreach ($this->root_unit_dtos as &$sob_dto) {
92

  
93
      $content_wrapper_markup = '';
94
      if($this->with_details){
95
        $field_unit_dto_render_array = compose_cdm_specimen_or_observation_dto_details_grid($sob_dto);
96
        $content_wrapper_markup = '<div class="unit-content-wrapper">' // allows to apply the borders between .derived-unit-tree-root and .unit-content
97
          . '<div class="unit-content derived-unit-details-grid">' . drupal_render($field_unit_dto_render_array) . '</div>'
98
          . '</div>';
99
      }
100
      $root_item = [
101
        '#prefix' => '<div class="derived-unit-tree">',
102
        '#suffix' => '</div>',
103
        '#type' => 'container',
104
        '#attributes' => [
105
          'class' => [
106
            'derived-unit-item derived-unit-tree-root',
107
            html_class_attribute_ref($sob_dto),
108
          ],
109
        ],
110
        'div-container' => [
111
          'root-item-and-sub-tree' => [
112
            markup_to_render_array($this->derived_units_tree_node_header($sob_dto)
113
              . $content_wrapper_markup),
114
          ],
115
        ],
117
    $list_items = $this->derived_units_as_list_items($this->root_unit_dtos);
116 118

  
117
      ];
118
      if (isset($sob_dto->derivatives) && sizeof($sob_dto->derivatives) > 0) {
119
        usort($sob_dto->derivatives, 'compare_specimen_or_observation_dtos');
120
        // children are displayed in a nested list.
121
        $root_item['div-container']['root-item-and-sub-tree'][] = $this->derived_units_sub_tree($sob_dto->derivatives);
122
      }
123
      $root_items[] = $root_item;
124
    }
125

  
126
    $root_items['footnotes'] = markup_to_render_array(render_footnotes());
127
    RenderHints::popFromRenderStack();
128

  
129
    return $root_items;
130
  }
131

  
132
  /**
133
   * @param array $unit_dtos
134
   *
135
   * @return array
136
   */
137
   private function derived_units_sub_tree(array $unit_dtos) {
138

  
139
    $list_items = $this->derived_units_as_list_items($unit_dtos);
140

  
141
    $derivation_tree = [
119
    $root_items = [
142 120
      '#theme' => 'item_list',
143 121
      '#type' => 'ul',
122
      '#prefix' => '<div class="item-tree">',
123
      '#suffix' => '</div>',
144 124
      '#attributes' => [
145
        // NOTE: class attribute "derived-unit-item" is important for consistency with subordinate <ul> elements produced by the drupal theme function
146
        'class' => CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE . ' derived-unit-item derived-unit-sub-tree',
147 125
      ],
148 126
      '#items' => $list_items,
149 127
    ];
150
    return $derivation_tree;
128

  
129
    $root_items['footnotes'] = markup_to_render_array(render_footnotes());
130
    RenderHints::popFromRenderStack();
131

  
132
    return $root_items;
133

  
151 134
  }
152 135

  
153 136
  /**
......
165 148
    $list_items = [];
166 149
    //we need one more item to contain the items of one level (fieldunit, derivate data etc.)
167 150
    foreach ($root_unit_dtos as &$sob_dto) {
151
      $has_sub_derivatives = isset($sob_dto->derivatives) && sizeof($sob_dto->derivatives) > 0;
168 152
      $item = [];
169
      $item['class'] = ['derived-unit-item ', html_class_attribute_ref($sob_dto)];
153
      $item['class'] = [
154
        'derived-unit-item ',
155
        html_class_attribute_ref($sob_dto),
156
        $this->itemCollapsedStateClassAttribute(),
157
        $this->collapsibleItemClassAttribute($has_sub_derivatives),
158
        $this->subItemsClassAttribute($has_sub_derivatives)
159
      ];
170 160
      // data" element of the array is used as the contents of the list item
171 161
      $item['data'] = [];
172 162
      $unit_content_markup = '';
173 163
      if($this->with_details){
174
        $units_render_array = compose_cdm_specimen_or_observation_dto_details_grid($sob_dto);
175
        $unit_content_markup = '<div class="unit-content derived-unit-details-grid">' . drupal_render($units_render_array) . '</div>';
164
        $unit_dto_render_array = compose_cdm_specimen_or_observation_dto_details_grid($sob_dto);
165
        $this->applyUnitContentGrid($unit_dto_render_array);
166
        $unit_content_markup = drupal_render($unit_dto_render_array);
176 167
      }
177
      $item['data'] = $this->derived_units_tree_node_header($sob_dto)
178
        . $unit_content_markup;
179
      if (isset($sob_dto->derivatives) && sizeof($sob_dto->derivatives) > 0) {
168
      $item['data'] = $this->applyItemWrapper(
169
        $this->derived_units_tree_node_header($sob_dto)
170
        . $unit_content_markup
171
        , $has_sub_derivatives);
172
      if ($has_sub_derivatives) {
180 173
        usort($sob_dto->derivatives, 'compare_specimen_or_observation_dtos');
181 174
        // children are displayed in a nested list.
182 175
        $item['children'] = $this->derived_units_as_list_items($sob_dto->derivatives);
......
187 180
    return $list_items;
188 181
  }
189 182

  
183

  
184
  /**
185
   * @param $unit_dto_render_array
186
   *
187
   * @return mixed
188
   *
189
   * FIXME: merge into compose_cdm_specimen_or_observation_dto_details_grid() again
190
   */
191
  function applyUnitContentGrid(&$unit_dto_render_array){
192
    $unit_dto_render_array['#prefix'] = '<div class="unit-content derived-unit-details-grid">';
193
    $unit_dto_render_array['#suffix'] = '</div>';
194
    return $unit_dto_render_array;
195
  }
196

  
197
  function applyItemWrapper($item_markup, $has_children){
198
    $sub_item_line_class_attribute = $has_children ? ' item-wrapper-with-sub-items' : '';
199
    return '<div class="item-wrapper' . $sub_item_line_class_attribute . '">' // allows to apply the borders between .derived-unit-tree-root and .unit-content
200
      . $item_markup
201
    . '</div>';
202
  }
203

  
190 204
  /**
191 205
   * @param $sob_dto
192 206
   *
......
196 210
    $link = '';
197 211
    $focused_attribute = '';
198 212
    $hover_effect_attribute = '';
213
    $collapse_open_icons = '';
214
    $unit_header_wrapper_sub_items_class_attr = '';
199 215
    if(is_uuid($this->getFocusedUnitUuid()) & $sob_dto->uuid == $this->getFocusedUnitUuid()) {
200 216
      $focused_attribute = " focused_item";
201 217
    } else {
......
208 224
    if($link) {
209 225
      $icon_link_markup = '<span class="page-link">' . $link . '</span>';
210 226
    }
211
    return '<div class="unit-header ' . $focused_attribute .'"><div class="unit-label' . $hover_effect_attribute .' "><span class="">' . symbol_for_base_of_record($sob_dto->recordBase->uuid). '</span> ' . $sob_dto->label . $icon_link_markup . '</div></div>';
227
    $has_sub_derivatives = isset($sob_dto->derivatives) && sizeof($sob_dto->derivatives) > 0;
228
    if($has_sub_derivatives){
229
      if($this->isCollapsible()){
230
        $collapse_open_icons = '<span class="tree-node-symbol tree-node-symbol-collapsible">'
231
          . font_awesome_icon_markup('fa-' . SYMBOL_COLLAPSIBLE_CLOSED)
232
          . '</span>';
233
      } else {
234
        $collapse_open_icons = '<span class="tree-node-symbol">'
235
          . font_awesome_icon_markup('fa-' . SYMBOL_COLLAPSIBLE_OPEN)
236
          . '</span>';
237
      }
238
    }
239
    if($has_sub_derivatives){
240
      $unit_header_wrapper_sub_items_class_attr = ' unit-header-wrapper-with-sub-items';
241
    }
242
    return '<div class="unit-header-wrapper' . $unit_header_wrapper_sub_items_class_attr . $focused_attribute . '"><div class="unit-header"><div class="unit-label' . $hover_effect_attribute .' ">' . $collapse_open_icons . '<span class="symbol">' . symbol_for_base_of_record($sob_dto->recordBase->uuid). '</span>' . $sob_dto->label . $icon_link_markup . '</div></div></div>';
212 243
  }
213 244

  
214 245
}

Also available in: Unified diff