<commit_before># -*- coding:utf-8 -*-
# --
# Copyright (c) 2012-2014 Net-ng.
# All rights reserved.
#
# This software is licensed under the BSD License, as described in
# the file LICENSE.txt, which you should have received as part of
# this distribution.
# --

from nagare.i18n import _, _N
from nagare import ajax, component, presentation, security, var

from kansha import notifications
from kansha.toolbox import overlay, remote
from kansha.board.boardconfig import WeightsSequenceEditor

from .boardsmanager import BoardsManager
from .comp import (Board, BoardDescription, BoardMember,
                   Icon)
from .comp import (BOARD_PRIVATE, BOARD_PUBLIC, BOARD_SHARED,
                   COMMENTS_OFF, COMMENTS_PUBLIC, COMMENTS_MEMBERS,
                   VOTES_OFF, VOTES_PUBLIC, VOTES_MEMBERS,
                   WEIGHTING_FREE, WEIGHTING_LIST, WEIGHTING_OFF)
from .boardconfig import BoardBackground, BoardConfig, BoardLabels, BoardProfile, BoardWeights

VISIBILITY_ICONS = {
    BOARD_PRIVATE: 'icon-lock',
    BOARD_PUBLIC: 'icon-unlocked',
    BOARD_SHARED: 'icon-earth'
}

@presentation.render_for(Board, model="menu")
def render_Board_menu(self, h, comp, *args):
    with h.div(class_='nav-menu'):
        with h.ul(class_='actions'):
            h << h.li(h.a(self.icons['preferences']).action(self.show_preferences))
            if security.has_permissions('edit', self):
                h << h.li(h.a(self.icons['add_list']).action(self.add_list))
                h << h.li(h.a(self.icons['edit_desc']).action(self.edit_description))
            if security.has_permissions('manage', self):
                h << h.li(h.a(self.icons['save_template']).action(self.save_template, comp))

            h << h.li(h.SyncRenderer().a(self.icons['export']).action(self.export))
            h << h.li(h.a(self.icons['history']).action(self.show_actionlog))

            if security.has_permissions('manage', self):
                h << h.li(h.SyncRenderer().a(
                    self.icons['archive'],
                    onclick=(
                        'return confirm(%s)' %
                        ajax.py2js(
                            _("This board will be archived. Are you sure?")
                        ).decode('UTF-8')
                    )
                ).action(self.archive, comp))
            else:
                h << h.li(h.SyncRenderer().a(
                    self.icons['leave'],
                    onclick=(
                        "return confirm(%s)" %
                        ajax.py2js(
                            _("You won't be able to access this board anymore. Are you sure you want to leave it anyway?")
                        ).decode('UTF-8')
                    )
                ).action(self.leave, comp))

        h << h.span(_(u'Board'), class_="menu-title", id='board-nav-menu')
        h << self.modal
    return h.root


@presentation.render_for(Board)
def render_Board(self, h, comp, *args):
    """Main board renderer"""
    security.check_permissions('view', self)
    h.head.css_url('css/themes/board.css')
    h.head.css_url('css/themes/%s/board.css' % self.theme)

    h.head.javascript_url('js/jquery-searchinput/jquery.searchinput.js')
    h.head.javascript_url('js/debounce.js')
    h.head.css_url('js/jquery-searchinput/styles/jquery.searchinput.min.css')
    h.head.javascript('searchinput', '''jQuery(document).ready(function ($) { $('#search').searchInput(); });''')
    title = '%s - %s' % (self.get_title(), self.app_title)
    h.head << h.head.title(title)
    if security.has_permissions('edit', self):
        h << comp.render(h.AsyncRenderer(), "menu")

    with h.div(class_='board'):
        if self.background_image_url:
            h << {'class': 'board ' + self.background_image_position,
                  'style': 'background-image:url(%s)' % self.background_image_url}
        with h.div(class_='header'):
            with h.div(class_='board-title', style='color: %s' % self.title_color):
                h << self.title.render(h.AsyncRenderer(), 0 if security.has_permissions('edit', self) else 'readonly')
            h << comp.render(h, 'switch')
        with h.div(class_='bbody'):
            h << comp.render(h.AsyncRenderer(), self.model)
    return h.root


@presentation.render_for(Board, 'search_results')
def render_Board_search_results(self, h, comp, *args):
    h << h.script('YAHOO.kansha.app.highlight_cards(%s);' % ajax.py2js(list(self.card_matches), h))
    h << comp.render(h, 'num_matches')
    return h.root


@presentation.render_for(Board, 'num_matches')
def render_Board_num_matches(self, h, comp, *args):
    if self.card_matches:

        if None in self.card_matches:
            h << h.span(_(u'No matches'), class_='nomatches')
        else:
            n = len(self.card_matches)
            h << (_N(u'%d match', u'%d matches', n) % n)
    else:
        h << u' '
    return h.root


@presentation.render_for(Board, 'switch')
def render_Board_item(self, h, comp, *args):
    reload_search = ajax.Update(component_to_update='show_results',
                                render=lambda renderer: comp.render(renderer, 'search_results'))
    h << h.script(u'''$(window).on('reload_search', function() { %s; })''' % reload_search.generate_action(41, h))

    with h.div(id='switch_zone'):
        if self.model == 'columns':
            search_cb = ajax.Update(
                action=self.search,
                component_to_update='show_results',
                render=lambda renderer: comp.render(renderer, 'search_results')
            ).generate_action(1, h).replace('this', 'elt')
            oninput = 'debounce(this, function(elt) { %s; }, 500)' % search_cb
            with h.div(id_='show_results'):
                h << comp.render(h, 'num_matches')
            if self.card_matches:
                if None in self.card_matches:
                    klass = 'nomatches'
                else:
                    klass = 'highlight'
            else:
                klass = ''
            h << h.input(type='text', id_='search', placeholder=_(u'search'),
                         value=self.last_search,
                         oninput=oninput,
                         class_=klass)
            #h << h.a(h.i(class_='icon-search', title=_('search')), class_='btn unselected')
            h << h.SyncRenderer().a(h.i(class_='icon-calendar'), title=_('Calendar mode'), class_='btn unselected').action(self.switch_view)
            h << h.SyncRenderer().a(h.i(class_='icon-list'), title=_('Board mode'), class_='btn disabled')
        else:
            h << h.SyncRenderer().a(h.i(class_='icon-calendar'), title=_('Calendar mode'), class_='btn disabled')
            h << h.SyncRenderer().a(h.i(class_='icon-list'), title=_('Board mode'), class_='btn unselected').action(self.switch_view)

    return h.root


@presentation.render_for(Board, 'item')
def render_Board_item(self, h, comp, *args):
    def answer():
        comp.answer(self.data.id)

    url = self.data.url
    with h.li:
        h << h.SyncRenderer().a(
            h.i(' ', class_=VISIBILITY_ICONS[self.data.visibility]),
            self.data.title,
            href=url, class_="boardItemLabel", title=self.data.description)

        with h.div(class_='actions'):
            h << self.comp_members.render(h, 'members')

            if security.has_permissions('manage', self):
                h << h.a(h.i(class_='ico-btn icon-box-add'), class_='archive', title=_(u'Archive this board')).action(self.archive, comp)
            elif security.has_permissions('leave', self):
                onclick = 'return confirm("%s")' % _("You won't be able to access this board anymore. Are you sure you want to leave it anyway?")
                h << h.SyncRenderer().a(h.i(class_='ico-btn icon-exit'), class_='leave', title=_(u'Leave this board'), onclick=onclick).action(self.leave, comp)
    return h.root


@presentation.render_for(Board, model="archived_item")
def render_Board_archived_item(self, h, comp, *args):
    with h.li:<commit_msg>Fixed alignment of shared boards on home page.<commit_after># -*- coding:utf-8 -*-
# --
# Copyright (c) 2012-2014 Net-ng.
# All rights reserved.
#
# This software is licensed under the BSD License, as described in
# the file LICENSE.txt, which you should have received as part of
# this distribution.
# --

from nagare.i18n import _, _N
from nagare import ajax, component, presentation, security, var

from kansha import notifications
from kansha.toolbox import overlay, remote
from kansha.board.boardconfig import WeightsSequenceEditor

from .boardsmanager import BoardsManager
from .comp import (Board, BoardDescription, BoardMember,
                   Icon)
from .comp import (BOARD_PRIVATE, BOARD_PUBLIC, BOARD_SHARED,
                   COMMENTS_OFF, COMMENTS_PUBLIC, COMMENTS_MEMBERS,
                   VOTES_OFF, VOTES_PUBLIC, VOTES_MEMBERS,
                   WEIGHTING_FREE, WEIGHTING_LIST, WEIGHTING_OFF)
from .boardconfig import BoardBackground, BoardConfig, BoardLabels, BoardProfile, BoardWeights

VISIBILITY_ICONS = {
    BOARD_PRIVATE: 'icon-lock',
    BOARD_PUBLIC: 'icon-unlocked',
    BOARD_SHARED: 'icon-earth'
}

@presentation.render_for(Board, model="menu")
def render_Board_menu(self, h, comp, *args):
    with h.div(class_='nav-menu'):
        with h.ul(class_='actions'):
            h << h.li(h.a(self.icons['preferences']).action(self.show_preferences))
            if security.has_permissions('edit', self):
                h << h.li(h.a(self.icons['add_list']).action(self.add_list))
                h << h.li(h.a(self.icons['edit_desc']).action(self.edit_description))
            if security.has_permissions('manage', self):
                h << h.li(h.a(self.icons['save_template']).action(self.save_template, comp))

            h << h.li(h.SyncRenderer().a(self.icons['export']).action(self.export))
            h << h.li(h.a(self.icons['history']).action(self.show_actionlog))

            if security.has_permissions('manage', self):
                h << h.li(h.SyncRenderer().a(
                    self.icons['archive'],
                    onclick=(
                        'return confirm(%s)' %
                        ajax.py2js(
                            _("This board will be archived. Are you sure?")
                        ).decode('UTF-8')
                    )
                ).action(self.archive, comp))
            else:
                h << h.li(h.SyncRenderer().a(
                    self.icons['leave'],
                    onclick=(
                        "return confirm(%s)" %
                        ajax.py2js(
                            _("You won't be able to access this board anymore. Are you sure you want to leave it anyway?")
                        ).decode('UTF-8')
                    )
                ).action(self.leave, comp))

        h << h.span(_(u'Board'), class_="menu-title", id='board-nav-menu')
        h << self.modal
    return h.root


@presentation.render_for(Board)
def render_Board(self, h, comp, *args):
    """Main board renderer"""
    security.check_permissions('view', self)
    h.head.css_url('css/themes/board.css')
    h.head.css_url('css/themes/%s/board.css' % self.theme)

    h.head.javascript_url('js/jquery-searchinput/jquery.searchinput.js')
    h.head.javascript_url('js/debounce.js')
    h.head.css_url('js/jquery-searchinput/styles/jquery.searchinput.min.css')
    h.head.javascript('searchinput', '''jQuery(document).ready(function ($) { $('#search').searchInput(); });''')
    title = '%s - %s' % (self.get_title(), self.app_title)
    h.head << h.head.title(title)
    if security.has_permissions('edit', self):
        h << comp.render(h.AsyncRenderer(), "menu")

    with h.div(class_='board'):
        if self.background_image_url:
            h << {'class': 'board ' + self.background_image_position,
                  'style': 'background-image:url(%s)' % self.background_image_url}
        with h.div(class_='header'):
            with h.div(class_='board-title', style='color: %s' % self.title_color):
                h << self.title.render(h.AsyncRenderer(), 0 if security.has_permissions('edit', self) else 'readonly')
            h << comp.render(h, 'switch')
        with h.div(class_='bbody'):
            h << comp.render(h.AsyncRenderer(), self.model)
    return h.root


@presentation.render_for(Board, 'search_results')
def render_Board_search_results(self, h, comp, *args):
    h << h.script('YAHOO.kansha.app.highlight_cards(%s);' % ajax.py2js(list(self.card_matches), h))
    h << comp.render(h, 'num_matches')
    return h.root


@presentation.render_for(Board, 'num_matches')
def render_Board_num_matches(self, h, comp, *args):
    if self.card_matches:

        if None in self.card_matches:
            h << h.span(_(u'No matches'), class_='nomatches')
        else:
            n = len(self.card_matches)
            h << (_N(u'%d match', u'%d matches', n) % n)
    else:
        h << u' '
    return h.root


@presentation.render_for(Board, 'switch')
def render_Board_item(self, h, comp, *args):
    reload_search = ajax.Update(component_to_update='show_results',
                                render=lambda renderer: comp.render(renderer, 'search_results'))
    h << h.script(u'''$(window).on('reload_search', function() { %s; })''' % reload_search.generate_action(41, h))

    with h.div(id='switch_zone'):
        if self.model == 'columns':
            search_cb = ajax.Update(
                action=self.search,
                component_to_update='show_results',
                render=lambda renderer: comp.render(renderer, 'search_results')
            ).generate_action(1, h).replace('this', 'elt')
            oninput = 'debounce(this, function(elt) { %s; }, 500)' % search_cb
            with h.div(id_='show_results'):
                h << comp.render(h, 'num_matches')
            if self.card_matches:
                if None in self.card_matches:
                    klass = 'nomatches'
                else:
                    klass = 'highlight'
            else:
                klass = ''
            h << h.input(type='text', id_='search', placeholder=_(u'search'),
                         value=self.last_search,
                         oninput=oninput,
                         class_=klass)
            #h << h.a(h.i(class_='icon-search', title=_('search')), class_='btn unselected')
            h << h.SyncRenderer().a(h.i(class_='icon-calendar'), title=_('Calendar mode'), class_='btn unselected').action(self.switch_view)
            h << h.SyncRenderer().a(h.i(class_='icon-list'), title=_('Board mode'), class_='btn disabled')
        else:
            h << h.SyncRenderer().a(h.i(class_='icon-calendar'), title=_('Calendar mode'), class_='btn disabled')
            h << h.SyncRenderer().a(h.i(class_='icon-list'), title=_('Board mode'), class_='btn unselected').action(self.switch_view)

    return h.root


@presentation.render_for(Board, 'item')
def render_Board_item(self, h, comp, *args):
    def answer():
        comp.answer(self.data.id)

    url = self.data.url
    with h.li:
        h << h.SyncRenderer().a(
            h.i(' ', class_=VISIBILITY_ICONS[self.data.visibility]),
            self.data.title,
            href=url, class_="boardItemLabel", title=self.data.description)

        with h.div(class_='actions'):
            h << self.comp_members.render(h, 'members')

            if security.has_permissions('manage', self):
                h << h.a(h.i(class_='ico-btn icon-box-add'), class_='archive', title=_(u'Archive this board')).action(self.archive, comp)
            elif security.has_permissions('leave', self):
                onclick = 'return confirm("%s")' % _("You won't be able to access this board anymore. Are you sure you want to leave it anyway?")
                h << h.SyncRenderer().a(h.i(class_='ico-btn icon-exit'), class_='leave', title=_(u'Leave this board'), onclick=onclick).action(self.leave, comp)
            else:
                # place holder for alignment and for future feature 'request membership'
                h << h.a(h.i(class_='ico-btn icon-user-check'), style='visibility:hidden')
    return h.root


@presentation.render_for(Board, model="archived_item")
def render_Board_archived_item(self, h, comp, *args):
    with h.li:
{'fraction_non_alphanumeric': 0.1494753635638461, 'fraction_numerical': 0.0028226053874946307, 'mean_word_length': 2.43477344573235, 'pattern_counts': {'":': 0, '<': 137, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6470490', 'n_tokens_mistral': 5130, 'n_tokens_neox': 4924, 'n_words': 989}