Пример #1
0
    def presentContent(self, **kwargs: object) -> XMLContent:
        proc = cast(Task_GET.Processor, kwargs['proc'])
        reports = proc.reports
        active = proc.active
        presenter = proc.presenter

        yield xhtml.div(class_='reporttabs')[(xhtml.div(
            class_='active' if active == label else None)[
                pageLink(self.name, proc.args.override(
                    report=label.casefold()))[presentLabel(label)],
                None if url is None else xhtml.
                a(href=url, target='_blank', title='Open report in new tab'
                  )[openInNewTabIcon.present(
                      **kwargs)]] for label, url in reports.items())]

        if presenter is not None:
            yield presenter.presentBody()
        elif active == 'Overview':
            yield self.presentOverview(**kwargs)
        elif active == 'Data':
            yield self.presentData(**kwargs)
        else:
            yield xhtml.iframe(class_='report',
                               src=reports[active],
                               sandbox=SANDBOX_RULES)
Пример #2
0
    def presentContent(self, **kwargs: object) -> XMLContent:
        proc = cast(ProductDetails_GET.Processor, kwargs['proc'])
        productDefId = proc.args.id
        producers = proc.producers
        consumers = proc.consumers

        numProducers = len(producers)
        numConsumers = len(consumers)
        deleteProduct = ( 'Delete this product: '
            'not possible, because it is currently being used by ',
            str(numProducers), ' ', pluralize('producer', numProducers),
            ' and ',
            str(numConsumers), ' ', pluralize('consumer', numConsumers), '.'
            ) if producers or consumers else pageLink(
                'ProductDelete', DeleteArgs(id = productDefId)
                )[ 'Delete this Product' ]

        yield xhtml.h3[ 'Details of product ', xhtml.b[ productDefId ], ':' ]
        yield xhtml.div(class_='hgroup wrap')[
            DetailsTable.instance,
            GraphPanel.instance
            ].present(graph=proc.graph, **kwargs)
        yield xhtml.p[
            pageLink('ProductEdit', proc.args)[ 'Edit this product' ],
            xhtml.br,
            deleteProduct
            ]
Пример #3
0
 def presentHeader(self, **kwargs: object) -> XMLContent:
     proc = cast(ProcT, kwargs['proc'])
     ccURL = cast(str, kwargs['ccURL'])
     userName = proc.user.name
     return xhtml.div(class_='titlebar')[
         xhtml.div(class_='title')[self.__title(proc)],
         xhtml.div(class_='info')[xhtml.a(
             href=ccURL +
             self.loginURL(**kwargs))['log in'] if userName is None else
                                  (createUserDetailsLink(userName).present(
                                      **kwargs), ' \u2013 ',
                                   xhtml.a(href=ccURL +
                                           logoutURL(proc.req))['log out']),
                                  xhtml.br,
                                  formatTime(getTime())],
         xhtml.div(
             class_='logo'
         )[xhtml.a(href=ccURL +
                   'About', title=f'SoftFab {VERSION}')[_logoIcon.present(
                       **kwargs)]]]
Пример #4
0
    def __presentLinkButton(self, button: LinkBarButton,
                            **kwargs: object) -> XMLNode:
        iconStyle = ['navicon']
        iconModifier = button.modifier
        if iconModifier is not IconModifier.NONE:
            iconStyle.append(self.__iconModifierStyle[button.modifier])

        return xhtml.div(class_='navthis' if button.active else None)[xhtml.a(
            href=button.url)[xhtml.span(
                class_=' '.join(iconStyle))[button.icon.present(**kwargs)],
                             xhtml.span(class_='navlabel')[button.label]]]
Пример #5
0
 def __presentBodyParts(self, req: Request, response: ResponseHeaders,
                        **kwargs: object) -> XMLContent:
     proc = cast(ProcT, kwargs['proc'])
     yield self.presentHeader(**kwargs)
     try:
         yield xhtml.div(class_='body')[self.__presentBody(req, **kwargs)]
         if proc.processingError is None:
             yield self.presentBackgroundScripts(**kwargs)
     except Exception as ex:
         logPageException(req, 'Error presenting page')
         response.setStatus(500, 'Error presenting page')
         yield from self.__formatError(req, ex)
Пример #6
0
class LinkBar(Widget):
    '''A bar which contains links to other pages.
    '''

    # These icons are referenced from the style sheet.
    styleRoot.addIcon('IconNew')
    styleRoot.addIcon('IconEdit')
    styleRoot.addIcon('IconDelete')

    __iconModifierStyle = {
        IconModifier.NEW: 'newicon',
        IconModifier.EDIT: 'editicon',
        IconModifier.DELETE: 'delicon',
    }

    __levelSep = xhtml.div(class_='level')['\u25B8']

    def __presentLinkButton(self, button: LinkBarButton,
                            **kwargs: object) -> XMLNode:
        iconStyle = ['navicon']
        iconModifier = button.modifier
        if iconModifier is not IconModifier.NONE:
            iconStyle.append(self.__iconModifierStyle[button.modifier])

        return xhtml.div(class_='navthis' if button.active else None)[xhtml.a(
            href=button.url)[xhtml.span(
                class_=' '.join(iconStyle))[button.icon.present(**kwargs)],
                             xhtml.span(class_='navlabel')[button.label]]]

    def __presentButtons(self, **kwargs: object) -> XMLContent:
        rootButtons = cast(Sequence[LinkBarButton], kwargs['rootButtons'])
        childButtons = cast(Sequence[LinkBarButton], kwargs['childButtons'])
        levelSep = self.__levelSep

        # Root path.
        for button in rootButtons:
            presentation = self.__presentLinkButton(button, **kwargs)
            isParent = not button.active
            if isParent or childButtons:
                presentation = presentation.addClass('rootpath')
            yield presentation
            if isParent:
                yield levelSep

        # Children.
        if childButtons:
            yield levelSep
            for button in childButtons:
                yield self.__presentLinkButton(button, **kwargs)

    def present(self, **kwargs: object) -> XMLContent:
        return xhtml.div(class_='linkbar')[self.__presentButtons(**kwargs)]
Пример #7
0
 def render_GET(self, request: TwistedRequest) -> object:
     presenter = self.presenter
     depth = len(request.prepath) - 1
     styleURL = '../' * depth + styleRoot.relativeURL
     request.write(b'<!DOCTYPE html>\n')
     request.write(xhtml.html[
         xhtml.head[fixedHeadItems,
                    presenter.headItems(),
                    xhtml.title[f'Report: {self.fileName}']].present(
                        styleURL=styleURL),
         xhtml.body[xhtml.div(class_='body')[presenter.presentBody()]]].
                   flattenXML().encode())
     request.finish()
     return NOT_DONE_YET
Пример #8
0
    def presentContent(self, **kwargs: object) -> XMLContent:
        proc = cast(FrameworkDetails_GET.Processor, kwargs['proc'])
        frameworkId = proc.args.id
        children = proc.children
        numChildren = len(children)
        deleteFramework = (
            'Delete this framework: not possible, '
            'because it is currently being used by ', str(numChildren), ' ',
            pluralize('task definition', numChildren), '.'
            ) if children else pageLink(
                'FrameworkDelete', DeleteArgs(id = frameworkId)
                )[ 'Delete this framework' ]

        yield xhtml.h3[ 'Details of framework ', xhtml.b[ frameworkId ], ':' ]
        yield xhtml.div(class_='hgroup wrap')[
            DetailsTable.instance,
            GraphPanel.instance
            ].present(graph=proc.graph, **kwargs)
        yield xhtml.p[
            pageLink('FrameworkEdit', proc.args)[ 'Edit this framework' ],
            xhtml.br,
            deleteFramework
            ]
Пример #9
0
 def __presentFooter(self, proc: PageProcessor, name: str) -> XMLContent:
     return xhtml.div(class_='export')['export: ', xhtml[', '].join(
         xhtml.a(
             href=proc.subItemRelURL(f'{name}.{fmt.ext}'),
             title=fmt.description,
         )[fmt.ext] for fmt in GraphFormat)]
Пример #10
0
 def present(self, **kwargs: object) -> XMLContent:
     proc = cast(PageProcessor, kwargs['proc'])
     name = cast(GraphBuilder, kwargs['graph']).name
     return xhtml.div(class_='graph')[xhtml.div[xhtml.object(
         data=proc.subItemRelURL(f'{name}.ui.svg'), type='image/svg+xml')],
                                      self.__presentFooter(proc, name)]
Пример #11
0
 def present(self, **kwargs: object) -> XMLContent:
     return xhtml.div(class_='linkbar')[self.__presentButtons(**kwargs)]
Пример #12
0
 def __presentGraph(self, name: str, **kwargs: object) -> XMLContent:
     try:
         svg = self.graphCache[name]
     except KeyError:
         svg = xhtml.span(class_='notice')['Graph rendering failed']
     return xhtml.div(class_='graph')[xhtml.div[svg]]