check_validate.html 6.96 KB
Newer Older
1 2 3 4 5 6 7
<!--
    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
-->
8
{{
9 10 11 12 13 14 15 16 17
    #--------------------------------------------------------------------------
    #
    # prepare the data
    #    - configure the Ext.data.Array for the statistics
    #    - configure the Ext.data.Array for the logs
    #    - build unique DIV identifier
    #    - write the title
    #
    #--------------------------------------------------------------------------
18
    import json
19

20
    #
21
    # configure the Ext.data.Array for the statistics
22
    #
23 24
    cfg = dict(sorters=['project'])

25
    cfg['fields'] = [{'name': 'records', 'type': 'int'},
26 27 28 29 30 31 32 33 34 35 36 37 38
                     {'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)
39 40

    #
41
    # configure the Ext.data.Array for the logs
42
    #
43 44 45 46 47 48 49 50 51 52 53 54 55
    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:
56 57 58 59 60 61 62 63 64
        for txt in row.txt:
            cfg['data'].append([row.category,
                                row.id,
                                ','.join(row.ids),
                                row.project,
                                row.title,
                                txt,
                                row.year])
        pass
65
    pass
66

67
    cfg_logsStore =  json.dumps(cfg)
68

69
    #
70
    # unique identifier for each DIV block associated to a grid
71 72 73
    #
    divlogs = abs(hash(cfg_logsStore))
    divstat = abs(hash(cfg_statStore))
74

75 76 77 78 79 80
    #
    # Write the Title on the HTML page
    #
    period = ""
    if selector.year:
        period = selector.year
81
    pass
82

83 84 85 86
    team = ""
    if selector.id_teams:
        team = db.teams[selector.id_teams].team
    pass
87

88 89 90 91
    project = ""
    if selector.id_projects:
        project = db.projects[selector.id_projects].project
    pass
92

93 94 95 96
    if team and not project:
        project = team
    elif team and project:
        project = "%s / %s" % (team, project)
97
    pass
98

99 100 101 102 103 104 105 106 107 108
    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)))

109
}}
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
<!--
    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.
     */

127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
    // bind the python and javascript variables
    // use the internationalization of web2py to translate grid header
    // MANDATORY: escape false to convert properly the quotes
    {{
        def write(value):
            return response.write("\n%s" % value, escape=False)

        write("var cfgLogsStore = %s," % cfg_logsStore)
        write("    cfgStatStore = %s," % cfg_statStore)
        write("    trCategory = '%s'," % T('Category'))
        write("    trCollection = '%s'," % T('Collection'))
        write("    trDuplicate = '%s'," % T('Duplicate'))
        write("    trError = '%s'," % T('Error'))
        write("    trId = '%s'," % T('Id'))
        write("    trInvalid = '%s'," % T('Invalid'))
        write("    trProject = '%s'," % T('Project'))
        write("    trRecords = '%s'," % T('Records'))
        write("    trStatistics = '%s'," % T('Statistics'))
        write("    trStatusOK = '%s'," % T('Status OK'))
        write("    trTitle = '%s'," % T('Title'))
        write("    trValidated = '%s'," % T('Validated'))
        write("    trYear = '%s';" % T('Year'))
    }}
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

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

    // 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},
165 166
            {text: trRecords, dataIndex: 'records', flex: 1, summaryType: 'sum'},
            {text: trStatusOK, dataIndex: 'ok', flex: 1, summaryType: 'sum'},
167
            {text: trValidated, dataIndex: 'validated', flex: 1, summaryType: 'sum'},
168
            {text: trInvalid, dataIndex: 'error', flex: 1, summaryType: 'sum'}
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
        ],
        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)))
}}