check_validate.html 7.08 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
<!--
    The python controller return:
        - logs (List of Storage)
        - selector (Selector)
        - counters (dict of Storage) the key are the project
          The storage keys are: found, ok, validated

    Prepare the data
        - Configuration for the Ext.data.Array
        - Unique DIV identifiers
        - Title
-->
13
{{
14
    import json
15

16
    #
17
    # transform the counters into a configuration of the Ext.data.Array
18
    #
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
    cfg = dict(sorters=['project'])

    cfg['fields'] = [{'name': 'found', 'type': 'int'},
                     {'name': 'ok', 'type': 'int'},
                     {'name': 'project', 'type': 'string'},
                     {'name': 'validated', 'type': 'int'},
                     {'name': 'error', 'type': 'int'}]

    cfg['data'] = []
    for project in counters:
        counter = counters[project]
        error = counter.found - counter.ok - counter.validated
        cfg['data'].append([counter.found, counter.ok, project, counter.validated, error])
    pass

    cfg_statStore =  json.dumps(cfg)
35 36

    #
37
    # transform the logs into a configuration for the Ext.data.Array
38
    #
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    cfg = dict(groupField='txt',
               sorters=['txt', 'title'])

    cfg['fields'] = [{'name': 'category', 'type': 'string'},
                     {'name': 'id', 'type': 'int'},
                     {'name': 'ids', 'type': 'string'},
                     {'name': 'project', 'type': 'string'},
                     {'name': 'title', 'type': 'string'},
                     {'name': 'txt', 'type': 'string'},
                     {'name': 'year', 'type': 'int'}]

    cfg['data'] = []
    for row in logs:
        cfg['data'].append([row.category,
                            row.id,
                            ','.join(row.ids),
                            row.project,
                            row.title,
                            ', '.join(row.txt),
                            row.year])
    pass
60

61
    cfg_logsStore =  json.dumps(cfg)
62

63 64 65 66 67
    #
    # identifier for each DIV block associated to a grid
    #
    divlogs = abs(hash(cfg_logsStore))
    divstat = abs(hash(cfg_statStore))
68

69 70 71 72 73 74
    #
    # Write the Title on the HTML page
    #
    period = ""
    if selector.year:
        period = selector.year
75
    pass
76

77 78 79 80
    team = ""
    if selector.id_teams:
        team = db.teams[selector.id_teams].team
    pass
81

82 83 84 85
    project = ""
    if selector.id_projects:
        project = db.projects[selector.id_projects].project
    pass
86

87 88 89 90
    if team and not project:
        project = team
    elif team and project:
        project = "%s / %s" % (team, project)
91
    pass
92

93 94 95 96 97 98 99 100 101 102
    title = "%s %s %s" % (T("Check and validate"), project, period)

    style = ["font-size: 12px;",
             "font-variant: small-caps;",
             "margin-left: 10px;",
             "margin-bottom: 3ex;",
             "margin-top: 2ex;"]

    response.write(P(title, _style="".join(style)))

103
}}
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
<!--
    The two DIV blocks to hook the Ext JS grid
-->
<div id="grid-{{=divstat}}"></div>
<div id="grid-{{=divlogs}}"></div>

<!--
    Inline javascript to instantiate and render the Ext JS Grid
-->
<script type="text/javascript">
    /**
     * Display the results of the Check and validate controller.
     * The report is built around two Ext.grid.Panels.
     * The first one summarizes the static while the second one
     * shows what happen for each publication found in the store.
     */

    var cfgLogsStore,
        cfgStatStore,
        gridLogs,
        gridStat,
        trCategory,
        trCollection,
        trDuplicate,
        trError,
        trFound,
        trId,
        trOk,
        trProject,
        trStatistics,
        trTitle,
        trValidated,
        trYear;

    /**
     * Renderer function returning the string Total
     */
    function rTotal() {
        return 'Total';
    }

    // bind the python and javascript variables
    // use the internationalization of web2py to translate grid header
    // MANDATORY: escape false to convert properly the quotes
    {{
        response.write("cfgLogsStore = %s;" % cfg_logsStore, escape=False)
        response.write("cfgStatStore = %s;" % cfg_statStore, escape=False)
        response.write("trCategory = '%s';" % T('Category'), escape=False),
        response.write("trCollection = '%s';" % T('Collection'), escape=False)
        response.write("trDuplicate = '%s';" % T('Duplicate'), escape=False),
        response.write("trError = '%s';" % T('Error'), escape=False),
        response.write("trFound = '%s';" % T('Found'), escape=False),
        response.write("trId = '%s';" % T('Id'), escape=False),
        response.write("trOk = '%s';" % T('Ok'), escape=False),
        response.write("trProject = '%s';" % T('Project'), escape=False),
        response.write("trStatistics = '%s';" % T('Statistics'), escape=False)
        response.write("trTitle = '%s';" % T('Title'), escape=False)
        response.write("trValidated = '%s';" % T('Validated'), escape=False),
        response.write("trYear = '%s';" % T('Year'), escape=False)
    }}

    // instantiate the grids for the Stat
    var gridStat = Ext.create('Ext.grid.Panel', {
        title: trStatistics,
        store: Ext.create('Ext.data.ArrayStore', cfgStatStore),
        columns: [
            {xtype: 'rownumberer'},
            {text: trProject, dataIndex: 'project', flex: 2, summaryRenderer: rTotal},
            {text: trFound, dataIndex: 'found', flex: 1, summaryType: 'sum'},
            {text: trOk, dataIndex: 'ok', flex: 1, summaryType: 'sum'},
            {text: trValidated, dataIndex: 'validated', flex: 1, summaryType: 'sum'},
            {text: trError, dataIndex: 'error', flex: 1, summaryType: 'sum'}
        ],
        forceFit: true,
        features: [{ftype:'summary'}],
        padding: "0 40 20 30",
        renderTo: 'grid-{{=divstat}}'
    });

    // instantiate the grids for the LOGs
    // The row are group per error and sorted by title.
    var gridLog = Ext.create('Ext.grid.Panel', {
        store: Ext.create('Ext.data.ArrayStore', cfgLogsStore),
        columns: [
            {xtype: 'rownumberer'},
            {text: trTitle, dataIndex: 'title', flex: 3},
            {text: trError, dataIndex: 'txt', flex: 1, hidden: true},
            {text: trId, dataIndex: 'id', flex: 0.2},
            {text: trDuplicate, dataIndex: 'ids', flex: 0.2, hidden: true},
            {text: trCategory, dataIndex: 'category', flex: 0.2, hidden: true},
            {text: trProject, dataIndex: 'project', flex: 0.5, hidden: true},
            {text: trYear, dataIndex: 'year', flex: 0.2, hidden: true}
        ],
        features: [
            {ftype:'grouping', groupHeaderTpl: '{name}', startCollapsed: true}
        ],
        forceFit: true,
        padding: "10 40 20 30",
        renderTo: 'grid-{{=divlogs}}'
    });

</script>

{{
    # processing time of the request
    from datetime import datetime

    delta = (datetime.now()-request.now).total_seconds()
    delta = T('Check and validate took %s seconds') % round(delta, 2)

        style = ["font-size: 10px;",
                 "margin-left: 10px;",
                 "margin-bottom: 3ex;",
                 "margin-top: 2ex;"]

    response.write(P(delta, _style="".join(style)))
}}