Exemple #1
0
def artists_render():
    data = this.props.data or this.state.data

    els = []
    if data:
        idx = {}
        for n, x in enumerate(data):
            idx[x] = n
        for a in sorted(
                data,
                key=lambda x: utils.get_object_value('preferred_name.name')):
            els.append(
                e(artistitem.ArtistLabel,
                  data=a,
                  key=a.id or utils.get_object_value('preferred_name.name', a)
                  or utils.get_object_value('names[0].name', a),
                  edit_mode=this.props.edit_mode,
                  update_data=this.artist_update_data,
                  data_key='[' + idx[a] + ']',
                  onRemove=this.on_remove))

    if this.props.edit_mode:
        els.append(
            e(
                ui.Modal,
                e(ui.Modal.Content,
                  onSubmit=this.on_new_artist,
                  scrolling=True,
                  onClose=this.on_modal_toggle,
                  defaultSelected=data,
                  as_=artistselector.ArtistSelector),
                trigger=e(ui.Icon,
                          onClick=this.on_modal_toggle,
                          size="small",
                          link=True,
                          js_name="plus",
                          color="blue"),
                dimmer="inverted",
                size="small",
                closeOnDocumentClick=True,
                centered=False,
                closeIcon=True,
                open=this.state.modal_open,
                onClose=this.on_modal_toggle,
            ))

    els = e(ui.Label.Group, els)

    return els
Exemple #2
0
def tag_on_input(e):
    if e.key == 'Enter':
        e.preventDefault()
        idata = this.state.tags_input
        itags = [x.strip() for x in str(idata).split(',')]

        data = this.props.data or this.state.data or {}
        special_namespace = "__namespace__"
        is_list = isinstance(data, list) or this.props.single
        nstag_names = []
        if is_list:
            for t in data:
                t_ns = utils.get_object_value('namespace.name', t)
                t_tag = utils.get_object_value('tag.name', t)
                nstag_names.append(t_ns + t_tag)

        for t in itags:
            if ':' in t:
                t = t.split(':', 1)
                ns = t[0].strip().capitalize() or None
                tag = t[1]
            else:
                ns = None
                tag = t

            if not tag:
                continue

            tag = tag.strip().lower()

            tag = {'name': tag}

            if is_list:
                nstag = {'tag': tag,
                         'namespace': {'name': ns or special_namespace}}
                nstag_name = nstag['namespace']['name'] + nstag['tag']['name']
                if nstag_name not in nstag_names:
                    nstag_names.append(nstag_name)
                    data = utils.update_object(None, data, nstag, op="append")
            else:
                data = utils.update_object(ns or special_namespace,
                                           data,
                                           tag,
                                           op="append",
                                           create_value=[],
                                           unique=lambda a, b: a['name'] == b['name'])

        this.setState({'tags_input': ''})
        this.update_data(data)
Exemple #3
0
def parodies_render():
    data = this.props.data or this.state.data

    els = []
    if data:
        for a in sorted(
                data,
                key=lambda x: utils.get_object_value('preferred_name.name')):
            els.append(
                e(parodyitem.ParodyLabel,
                  data=a,
                  key=a.id or utils.get_object_value('preferred_name.name', a)
                  or utils.get_object_value('names[0].name', a),
                  edit_mode=this.props.edit_mode,
                  update_data=this.props.update_data,
                  data_key=this.props.data_key,
                  onRemove=this.on_remove))

    if this.props.edit_mode:
        els.append(
            e(
                ui.Modal,
                e(ui.Modal.Content,
                  onSubmit=this.on_new_parody,
                  scrolling=True,
                  onClose=this.on_modal_toggle,
                  defaultSelected=data,
                  as_=parodyselector.ParodySelector),
                trigger=e(ui.Icon,
                          onClick=this.on_modal_toggle,
                          size="small",
                          link=True,
                          js_name="plus",
                          color="purple"),
                dimmer="inverted",
                size="small",
                closeOnDocumentClick=True,
                centered=False,
                closeIcon=True,
                open=this.state.modal_open,
                onClose=this.on_modal_toggle,
            ))

    els = e(ui.Label.Group, els)

    return els
Exemple #4
0
def selector_on_item(e, data):
    selected = this.state.selected
    selected_ids = [a.id for a in selected]
    selected_def = this.props.defaultSelected
    selected_def_ids = [a.id for a in selected_def] if selected_def else []
    if data.id in selected_ids:
        selected = utils.remove_from_list(selected, data)
    if data.id in selected_def_ids:
        pass
    else:
        key = 'name'
        selected = utils.update_object(
            None,
            this.state.selected,
            data,
            op="append",
            unique=lambda a, b: a['id'] == b['id']
            if a['id'] or b['id'] else utils.get_object_value(
                key, a) == utils.get_object_value(key, b))
    this.setState({'selected': selected})
Exemple #5
0
def remove_tag(e, d):
    tag = e.target.dataset.tag
    ns = e.target.dataset.namespace or '__namespace__'
    data = this.props.data or this.state.data
    if tag and ns and data:
        if isinstance(data, list) or this.props.single:
            f = None
            for t in data:
                has_ns = utils.get_object_value('namespace.name', t) == ns
                has_tag = utils.get_object_value('tag.name', t) == tag
                if has_ns and has_tag:
                    f = t
                    break
            if f:
                data = utils.remove_from_list(data, f, key=None)
        else:
            tags = data[ns]
            data[ns] = utils.remove_from_list(tags, tag, key="name")
            if not len(data[ns]):
                del data[ns]
        this.update_data(data)
Exemple #6
0
def selector_render():
    data = this.props.data or this.state.data
    selected = this.state.selected
    on_remove = this.on_item_remove
    top_el = e(
        ui.Grid,
        e(
            ui.Grid.Row,
            e(
                ui.Grid.Column,
                e(ui.Button,
                  tr(this, "ui.t-select", "select"),
                  onClick=this.on_submit,
                  floated="right",
                  size="small",
                  primary=True) if len(selected) else None,
                e(ui.Input,
                  label={
                      'as': 'a',
                      'basic': True,
                      'content': tr(this, "ui.b-new", "New"),
                      'onClick': this.on_new_item
                  } if this.state.search_query else js_undefined,
                  size="mini",
                  value=this.state.search_query,
                  icon='search',
                  fluid=True,
                  onChange=this.update_search),
            ),
        ),
        e(
            ui.Grid.Row,
            e(
                ui.Grid.Column,
                e(ui.Label.Group, [
                    e(circleitem.CircleLabel,
                      data=a,
                      key=a.id or utils.get_object_value('name', a)
                      or utils.get_object_value('name', a),
                      showRemove=True,
                      onRemove=on_remove) for a in selected
                ]))))

    selected_ids = [a.id for a in selected]
    if this.props.defaultSelected:
        defaultSelected = this.props.defaultSelected
        selected_ids.extend([a.id for a in defaultSelected])
    a_els = []
    if data:
        for a in data:
            a_els.append(
                e(
                    circleitem.CircleItem,
                    data=a,
                    active=a.id in selected_ids,
                    key=a.id,
                    selection=True,
                    onClick=this.on_item,
                ))
    if len(a_els):
        a_els.append(
            e(
                ui.Segment,
                e(
                    ui.Visibility,
                    context=this.state.context_el,
                    onTopVisible=this.get_more,
                    once=False,
                    fireOnMount=True,
                ),
                key="inf",
                basic=True,
                loading=this.state.loading_more,
            ))

    els = e(ui.List,
            a_els,
            divided=True,
            relaxed=True,
            selection=True,
            link=True,
            size=this.props.size if this.props.size else "small",
            className="max-400-h min-300-h " + this.props.className
            if this.props.className else "max-600-h min-500-h",
            verticalAlign="middle")

    return e(
        ui.Segment,
        top_el,
        e(
            ui.Ref,
            els,
            innerRef=this.get_context_el,
        ),
        basic=True,
        loading=this.state.loading,
    )