예제 #1
0
    def iterRows(self, **kwargs: object) -> Iterator[XMLContent]:
        proc = cast(PageProcessor, kwargs['proc'])
        resTypeDB: ResTypeDB = getattr(proc, 'resTypeDB')
        resWidget = dropDownList(name='type')[resTypeOptions(resTypeDB)]

        # pylint: disable=line-too-long
        reqMap: DefaultDict[str, DefaultDict[str, List[Tuple[
            bool, List[str]]]]] = defaultdict(lambda: defaultdict(list))
        #       type -> ref -> (inherited, caps)*
        parentClaim = self.__parentClaim
        if parentClaim is not None:
            for spec in parentClaim:
                ref = spec.reference
                resTypeName = spec.typeName
                reqMap[resTypeName][ref].append(
                    (True, sorted(spec.capabilities)))
        args = cast(_ResourceRequirementsArgs, proc.args)
        for ref, resTypeName, caps in zip(args.ref, args.type, args.caps):
            reqMap[resTypeName][ref].append((False, sorted(caps.split())))

        for resType in iterResourceTypes(resTypeDB):
            resTypeName = resType.getId()
            refMap = reqMap[resTypeName]

            for ref in sorted(refMap.keys()):
                capMap = dict(refMap[ref])
                inherited = True in capMap
                if inherited or resTypeName == taskRunnerResourceTypeName:
                    # Type and reference are fixed.
                    typeControl: XMLContent = (presentResTypeName(resTypeName),
                                               hiddenInput(name='type',
                                                           value=resTypeName))
                    refControl: XMLContent = (xhtml.span(class_='var')[ref],
                                              hiddenInput(name='ref',
                                                          value=ref))
                else:
                    # User can edit type and reference.
                    typeControl = resWidget(selected=resTypeName)
                    refControl = _refInput(value=ref)

                if inherited:
                    capsControl = _CapabilitiesTable.instance.present(
                        resType=resTypeName, capMap=capMap, **kwargs)
                else:
                    capsControl = _capsInput(value=' '.join(capMap[False]))

                yield typeControl, refControl, capsControl

        # Empty entry at the end.
        yield resWidget(selected=''), _refInput(value=''), _capsInput(value='')
예제 #2
0
    def presentContent(self, **kwargs: object) -> XMLContent:
        proc = cast(BatchExecute_GET.Processor, kwargs['proc'])
        for notice in proc.notices:
            yield xhtml.p(class_='notice')[notice]
        configs = proc.configs
        if configs:
            yield xhtml.h3['Selected configurations:']
            yield BatchConfigTable.instance.present(**kwargs)

            taskSet = proc.taskSet
            if taskSet is None:
                yield xhtml.p['Cannot execute because of conflict.']
            else:
                yield makeForm(args=ParentArgs.subset(proc.args))[
                    BatchInputTable.instance, submitButtons, decoration[
                        xhtml.hr, ParamTable.instance,
                        # Second set of submit buttons after parameter tables.
                        submitButtons],
                    (hiddenInput(name=f'config.{i:d}', value=cfg.getId())
                     for i, cfg in enumerate(configs)), ].present(
                         taskSet=taskSet, **kwargs)
                return
        else:
            yield xhtml.h3['No configurations selected']

        yield xhtml.p[xhtml.a(
            href=proc.args.refererURL or parentPage)['Back to Configurations']]
예제 #3
0
    def presentContent(self, **kwargs: object) -> XMLContent:
        proc = cast(ConfigTagsBase.Processor[ArgsT], kwargs['proc'])
        for notice in proc.notices:
            yield xhtml.p(class_='notice')[notice]
        configs = proc.configs
        if configs:
            yield xhtml.h3['Selected Configurations:']
            yield TagConfigTable.instance.present(**kwargs)

            yield xhtml.h3['Common Selection Tags:']
            tagKeys = proc.project.getTagKeys()
            commonTags = getCommonTags(tagKeys,
                                       (config.tags for config in configs))
            yield makeForm(args=ParentArgs.subset(proc.args).override(
                sel={config.getId()
                     for config in configs}
            ))[ConfigTagValueEditTable.instance,
               xhtml.p[actionButtons(Actions)],
               (hiddenInput(name=f'commontags.{index:d}', value=tagName)
                for index, tagKey in enumerate(tagKeys)
                for tagName in commonTags[tagKey])].present(
                    getValues=lambda key: valuesToText(commonTags[key]),
                    **kwargs)
        else:
            yield (xhtml.h3['No configurations selected'],
                   xhtml.p[xhtml.a(href=proc.args.refererURL or parentPage)
                           ['Back to Configurations']])
예제 #4
0
 def iterRows(self, **kwargs: object) -> Iterator[XMLContent]:
     taskSet = cast(TaskSetWithInputs, kwargs['taskSet'])
     grouped = taskSet.getInputsGrouped()
     localInputs = taskSet.hasLocalInputs()
     resourceDB: ResourceDB = getattr(kwargs['proc'], 'resourceDB')
     taskRunners = None
     for group, groupInputs in grouped:
         first: Optional[str] = None
         for inp in groupInputs:
             inputName = inp.getName()
             cells: List[XMLContent] = [inputName]
             prodType = inp.getType()
             local = inp.isLocal()
             locator = inp.getLocator() or ''
             if prodType is ProductType.TOKEN:
                 if local:
                     cells.append('token')
                 else:
                     # Global token: do not include this.
                     continue
             else:
                 cells.append(
                     textInput(name='prod.' + inputName,
                               value=locator,
                               size=80))
             if localInputs and first is None:
                 if local:
                     if taskRunners is None:
                         taskRunners = sorted(runner.getId(
                         ) for runner in resourceDB.iterTaskRunners(
                         ) if self.filterTaskRunner(
                             # TODO: Passing "inp" should not be needed,
                             #       but this requires non-trivial
                             #       changes in BatchExecute.
                             runner,
                             taskSet,
                             group,
                             inp))
                     cellData: XMLContent = dropDownList(
                         name='local.' + inputName,
                         selected=inp.getLocalAt() or '',
                         required=True)[emptyOption(
                             disabled=True)['(select Task Runner)'],
                                        taskRunners]
                 else:
                     cellData = '-'
                 cells.append(cell(rowspan=len(groupInputs))[cellData])
             if first is None:
                 first = inputName
             elif local:
                 cells[0] = (cells[0],
                             hiddenInput(name='lref.' + inputName,
                                         value=first))
             yield cells
예제 #5
0
 def __presentFormBody(self, user: User) -> XMLContent:
     yield xhtml.p[ 'Enter information about new user:'******'loginpass', value='')
     else:
         yield xhtml.p[
             'To verify your identity, '
             'please also enter your own password:'
             ]
         yield ReqPasswordTable.instance
     yield xhtml.p[ actionButtons(Actions) ]
예제 #6
0
def presentFormBody(**kwargs: object) -> XMLContent:
    proc = cast(PageProcessor[PasswordMsgArgs], kwargs['proc'])
    yield xhtml.p['Please enter a new password for user ',
                  xhtml.b[proc.user.name], ':']
    yield NewPasswordTable.instance
    if proc.user.name is None:
        yield hiddenInput(name='loginpass', value='')
    else:
        yield xhtml.p['To verify your identity, '
                      'please also enter your old password:']
        yield ReqPasswordTable.instance
    yield xhtml.p[actionButtons(Actions)]
예제 #7
0
 def presentCell(self, record: UserAccount, **kwargs: object) -> XMLContent:
     proc = cast(UserList_GET.Processor, kwargs['proc'])
     role = record.uiRole
     if proc.canChangeRoles:
         userName = record.getId()
         return makeForm(
             formId=f'role_{userName}', args=proc.args,
             setFocus=False)[hiddenInput(name='user', value=userName),
                             roleDropDownList(selected=role), ' ',
                             submitButton['Apply']].present(**kwargs)
     else:
         return role
예제 #8
0
 def iterRows(self, **kwargs: object) -> Iterator[XMLContent]:
     getValues = cast(Callable[[str], Sequence[str]], kwargs['getValues'])
     tagCache = self.getTagCache(**kwargs)
     tagKeys = tagCache.getKeys()
     for index, key in enumerate(tagKeys):
         indexStr = str(index)
         inputName = 'tagvalues.' + indexStr
         values = sorted(tagCache.getValues(key))
         yield (preserveSpaces(key),
                (hiddenInput(name='tagkeys.' + indexStr, value=key),
                 textInput(name=inputName, value=getValues(key), size=80)),
                cell(class_='taglist')[dropDownList(
                    selected='',
                    style='width: 100%',
                    onchange="AddTagValue('" + inputName +
                    "', event);")[chain([''], values)]] if values else cell)
예제 #9
0
def selectDialog(formAction: str, tagCache: TagCache, filterTable: XMLContent,
                 basketTable: XMLContent, title: str,
                 **kwargs: object) -> Iterator[XML]:
    proc = cast(SelectProcMixin[BasketArgs, SelectableRecordABC],
                kwargs['proc'])
    tagKey = proc.args.tagkey
    tagValue = proc.args.tagvalue
    selected = proc.selected
    filtered = proc.filtered

    cleanedArgs = proc.args.override(sel=selected, bsk=set(), action=None)

    yield xhtml.p[f'Number of {proc.db.description}s shown: '
                  f'{len(filtered):d} of {len(proc.db):d}']

    def actionButtons() -> List[XMLContent]:
        return [
            submitButton(name='action', value=value)[label]
            for value, label, action_ in proc.iterActions()
        ]

    tagKeys = tagCache.getKeys()
    if len(tagKeys) == 0:
        yield makeForm(
            formId='selform1',
            action=formAction,
            method='get',
            args=cleanedArgs
        )[filterTable, addRemoveStyleScript, _selectScript2,
          script["window.onload = function() { RowSelection('selform1'); }"],
          xhtml.p[xhtml['\u00A0'].join(
              chain([
                  _scriptButton(True)[_selButtonLabel],
                  _scriptButton(False)[_resButtonLabel]
              ], actionButtons()))]].present(getRowStyle=lambda record: None,
                                             selectName='sel',
                                             selectFunc=lambda recordId:
                                             (recordId in selected, True),
                                             **kwargs)
        return

    def createKeyCell(key: str) -> XML:
        label = preserveSpaces(key) if key else '(show all)'
        if key == tagKey:
            return xhtml.td(class_='navthis')[label]
        else:
            return xhtml.td(class_='navother')[pageLink(
                formAction,
                cleanedArgs.override(tagkey=key, tagvalue=None,
                                     first=0))[label]]

    yield xhtml.table(
        class_='nav')[xhtml.tbody[xhtml.tr[xhtml.th['Tag Keys:'],
                                           (createKeyCell(key)
                                            for key in chain(tagKeys, ['']))]]]

    if tagKey:

        def createTagCell(value: str) -> XML:
            label = preserveSpaces(value) if value else '(undefined)'
            if value == tagValue:
                return xhtml.td(class_='navthis')[label]
            else:
                return xhtml.td(class_='navother')[pageLink(
                    formAction, cleanedArgs.override(tagvalue=value,
                                                     first=0))[label]]

        valueTable: XMLContent = xhtml.table(
            class_='nav')[xhtml.tbody[xhtml.tr[xhtml.th['Tag Values:']], (
                xhtml.tr[createTagCell(value)]
                for value in sorted(tagCache.getValues(tagKey)) + [''])]]
    else:
        valueTable = None

    def selectedDisable(recordId: str) -> Tuple[bool, bool]:
        sel = recordId in selected
        return sel, not sel

    if filtered - selected:
        buttons: List[XMLContent] = [
            _scriptButton(True)[_selButtonLabel], resetButton[_resButtonLabel],
            submitButton(name='action', value='add')
        ]
        if not selected:
            buttons += actionButtons()
        setFocus = True
    else:
        buttons = [
            disabledButton[_selButtonLabel],
            disabledButton[_resButtonLabel],
            disabledButton['Add'],
        ]
        setFocus = False

    def rowStyle(record: SelectableRecord) -> Optional[str]:
        return 'selected' if record.getId() in selected else None

    yield makeForm(
        formId='selform1',
        action=formAction,
        method='get',
        args=cleanedArgs,
        setFocus=setFocus
    )[hgroup[valueTable, filterTable], _selectScript1,
      # Store basket contents.
      # There will be checkboxes named "sel" as well; the results from the
      # active checkboxes will be merged with these hidden fields.
      (hiddenInput(name='sel', value=item) for item in selected),
      xhtml.p[xhtml['\u00A0'].join(buttons)]].present(
          getRowStyle=rowStyle,
          selectName='sel',
          selectFunc=selectedDisable,
          **kwargs)

    if selected:
        yield xhtml.hr
        yield xhtml.h2[title]
        yield xhtml.p[f'Number of {proc.db.description}s in basket: '
                      f'{len(proc.selectedRecords):d}']
        yield makeForm(
            formId='selform2',
            action=formAction,
            method='get',
            args=cleanedArgs,
            setFocus=not setFocus)[basketTable, xhtml.p[xhtml['\u00A0'].join(
                chain([
                    _scriptButton(True, 'bsk')[_selButtonLabel],
                    resetButton[_resButtonLabel],
                    submitButton(name='action', value='remove')
                ], actionButtons()))]].present(
                    getRowStyle=lambda record: 'selected',
                    selectName='bsk',
                    selectFunc=lambda recordId: (False, True),
                    **kwargs)