def _get_element(self, **kwargs) -> htmler.Element: cont = htmler.TagLessElement() cont.append_child(htmler.H2(lang.t('theming@installed_themes'))) table = cont.append_child( htmler.Table(css='table table-striped table-bordered table-hover')) t_head = table.append_child(htmler.Tr()) t_head.append_child(htmler.Th(lang.t('theming@name'))) t_head.append_child(htmler.Th(lang.t('theming@version'))) t_head.append_child(htmler.Th(lang.t('theming@author'))) t_head.append_child(htmler.Th(lang.t('theming@url'))) t_head.append_child(htmler.Th(lang.t('theming@actions'))) t_body = table.append_child(htmler.Tbody()) for theme in _api.get_all().values(): tr = t_body.append_child(htmler.Tr()) tr.append_child(htmler.Td(theme.name)) tr.append_child(htmler.Td(theme.version)) tr.append_child( htmler.Td( htmler.A(theme.author['name'], href=theme.author['url'], target='_blank'))) tr.append_child( htmler.Td(htmler.A(theme.url, href=theme.url, target='_blank'))) actions = htmler.TagLessElement(child_sep=' ') if _api.get().name != theme.name: # 'Switch' button btn_switch = htmler.A( title=lang.t('theming@switch_to_this_theme'), href='#', role='button', css='btn btn-default btn-light btn-sm button-switch', data_package_name=theme.package_name) btn_switch.append_child(htmler.I(css='fa fas fa-power-off')) actions.append_child(btn_switch) # 'Uninstall' button btn_delete = htmler.A( title=lang.t('theming@uninstall_theme'), href='#', role='button', css='btn btn-danger btn-sm button-uninstall', data_package_name=theme.package_name) btn_delete.append_child(htmler.I(css='fa fas fa-trash')) actions.append_child(btn_delete) tr.append_child(htmler.Td(actions)) return cont
def _get_element(self, **kwargs) -> htmler.Element: """Hook """ self._data['header-hidden'] = self._is_header_hidden if self._max_rows: self._data['max-rows'] = self._max_rows base_row = self._get_widgets() table = htmler.Table(css='content-table') # Header thead = htmler.Thead(css='hidden sr-only slots-header') table.append_child(thead) row = htmler.Tr() thead.append_child(row) row.append_child(htmler.Th(' ', css='order-col')) for w in self._get_widgets(): row.append_child(htmler.Th(w.label, css='widget-col')) row.append_child(htmler.Th(css='actions-col')) # Table body tbody = htmler.Tbody(css='slots') table.append_child(tbody) # Base slot tbody.append_child( self._get_row(base_row, add_css='base hidden sr-only')) # Rows for em in self._get_rows(): tbody.append_child(em) # Footer tfoot = htmler.Tfoot() tfoot_tr = htmler.Tr() tfoot_td = htmler.Td(colspan=len(self._get_widgets()) + 2) tfoot_tr.append_child(tfoot_td) tfoot.append_child(tfoot_tr) table.append_child(tfoot) if self._enabled: add_btn = htmler.A( href='#', css='button-add-slot btn btn-default btn-light btn-sm') if self._add_btn_icon: add_btn.append_child(htmler.I(css=self._add_btn_icon)) if self._add_btn_label: add_btn.append_child(self._add_btn_label) tfoot_td.append_child(add_btn) return table
def _get_row(self, widgets: List[Abstract], row_num: int = 0, add_css: str = '') -> htmler.Tr: """Build single row """ slot_tr = htmler.Tr(css='slot ' + add_css) slot_tr.append_child( htmler.Td('[{}]'.format(row_num + 1), css='order-col')) # Widgets for w in widgets: w.name = self._get_row_widget_name(w) w.form_group = False w_td = htmler.Td(css='widget-col widget-col-' + w.uid) w_td.append_child(w.renderable()) slot_tr.append_child(w_td) # Actions actions_td = htmler.Td(css='actions-col') slot_tr.append_child(actions_td) # 'Remove' button if self._enabled: remove_btn = htmler.A( href='#', css='button-remove-slot btn btn-sm btn-danger') remove_btn.append_child( htmler.I(css='fa fas fa-icon fa-remove fa-times')) actions_td.append_child(remove_btn) return slot_tr
def _get_element(self, **kwargs) -> htmler.Element: table = htmler.Table(css='table table-bordered table-hover') for part in self._thead, self._tbody, self._tfoot: if not part: continue if part is self._thead: t_part = htmler.Thead() elif part is self._tbody: t_part = htmler.Tbody() else: t_part = htmler.Tfoot() table.append_child(t_part) # Append rows for row in part: tr = htmler.Tr() for cell in row: td = htmler.Th() if part is self._thead else htmler.Td() if isinstance(cell, dict): if 'content' in cell: td.append_text(cell.pop('content')) for attr in cell.keys(): td.set_attr(attr, cell[attr]) elif isinstance(cell, str): td.append_text(cell) else: raise TypeError('Dict or str expected, got {}'.format( type(cell))) tr.append_child(td) t_part.append_child(tr) return table
def _get_element(self, **kwargs) -> htmler.Element: """Get table HTML skeleton """ c_lang = lang.get_current() if c_lang == 'ru': locale = 'ru-RU' elif c_lang == 'uk': locale = 'uk-UA' else: locale = 'en-US' # Table skeleton table = htmler.Table( css='hidden sr-only', data_locale=locale, data_url=self._rows_url, data_show_refresh='true', data_search=str(self._search).lower(), data_pagination='true', data_side_pagination='server', data_page_size='10', data_striped='true', data_sort_name=self._default_sort_field, data_sort_order=self._default_sort_order, data_cookie='true', data_cookie_id_table=self.uid, data_cookies_enabled= "[bs.table.sortOrder,bs.table.sortName,bs.table.pageNumber,bs.table.pageList]", data_cookie_expire='1y', data_cookie_storage='localStorage', ) t_head = htmler.Thead() t_body = htmler.Tbody() table.append_child(t_head) table.append_child(t_body) # Table head row t_head_row = htmler.Tr() t_head.append_child(t_head_row) # Checkbox column if self._checkbox: t_head_row.append_child( htmler.Th(data_field='__state', data_checkbox='true', css='td-row-actions')) # Head row's cells for f in self._data_fields: t_head_row.append_child( htmler.Th( f[1], data_field=f[0], data_sortable='true' if f[2] else 'false', css='td-field-' + f[0], )) r = htmler.TagLessElement() r.append_child(self._toolbar) r.append_child(table) return r