check_validate.html 10.7 KB
Newer Older
1
{{
2 3 4 5 6 7 8 9

    #--------------------------------------------------------------------------
    # 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
    #
10 11 12
    #--------------------------------------------------------------------------
    #
    # prepare the data
13
    #    - create URL for id, ids and title
14 15
    #    - configure the Ext.data.Array for the statistics
    #    - configure the Ext.data.Array for the logs
16 17 18 19 20
    #    - configure the field name for the Ext.form.Panel
    #    - the title of the HTML page
    #    - the DIV blocks
    #    - the HTML page footer
    #    - export python variables to the javascript
21 22
    #
    #--------------------------------------------------------------------------
23
    import json
24
    from datetime import datetime
25

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    #
    # create the URL to compare id and ids
    # modified the content of the row.title
    #
    for row in logs:
        for i in range(len(row.ids)):
            url = URL('wizards',
                      'compare_publications',
                       vars=dict(id1=row.id, id2=row.ids[i]))

            row.ids[i] = str(A(row.ids[i], _href=url, _target="_blank"))
        pass
    pass

    #
    # create the URL pointing to the record in the havest store
    # modified the content of the row.ids
    #
    for row in logs:
        origin = db.publications[row.id].origin
        if origin:
47 48
            origin = origin.split(",")
            origin = origin[0].strip()
49 50 51 52 53 54 55 56 57 58 59 60 61
            row.title = str(A(row.title, _href=origin, _target="_blank"))
        pass
    pass

    #
    # create the URL to edit the id
    # modified the content of the row.id
    #
    for row in logs:
        script = "javascript:onGridLogClick(%i)" % row.id
        row.id = str(A(row.id, _href=script))
    pass

62
    #
63
    # configure the Ext.data.Array for the statistics
64
    #
65 66
    cfg = dict(sorters=['project'])

67
    cfg['fields'] = [{'name': 'records', 'type': 'int'},
68 69 70 71 72 73
                     {'name': 'ok', 'type': 'int'},
                     {'name': 'project', 'type': 'string'},
                     {'name': 'validated', 'type': 'int'},
                     {'name': 'error', 'type': 'int'}]

    cfg['data'] = []
74

75 76 77 78 79 80 81
    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)
82 83

    #
84
    # configure the Ext.data.Array for the logs
85
    #
86 87 88 89
    cfg = dict(groupField='txt',
               sorters=['txt', 'title'])

    cfg['fields'] = [{'name': 'category', 'type': 'string'},
90
                     {'name': 'id', 'type': 'string'},
91 92 93 94 95 96 97
                     {'name': 'ids', 'type': 'string'},
                     {'name': 'project', 'type': 'string'},
                     {'name': 'title', 'type': 'string'},
                     {'name': 'txt', 'type': 'string'},
                     {'name': 'year', 'type': 'int'}]

    cfg['data'] = []
98

99
    for row in logs:
100 101 102 103 104 105 106 107 108
        for txt in row.txt:
            cfg['data'].append([row.category,
                                row.id,
                                ','.join(row.ids),
                                row.project,
                                row.title,
                                txt,
                                row.year])
        pass
109
    pass
110

111
    cfg_logsStore =  json.dumps(cfg)
112

113
    #
114
    # configure the field name for the Ext.form.Panel
115
    #
116
    # HACK:
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
    # simplify the encoding of the field name for the form (TableField → field)
    # NOTE: for publication fields are organized in tabPanel
    # FIXME: awfull piece of code. Have to solve it in plugin_dbbui
    #
    items = json.loads(publications_fields)

    for tabPanel in items:
        for tab in tabPanel['items']:
            for field in tab['items']['items']:
                if field['xtype'] == 'fieldcontainer':
                    for el in field['items']:
                        el['name'] = el['name'].replace("Publications", "").lower()
                    pass
                else:
                    field['name'] = field['name'].replace("Publications", "").lower()
                pass
            pass
        pass
    pass

    publications_fields = json.dumps(items)

139
    #
140
    # the title of the HTML page
141 142 143 144
    #
    period = ""
    if selector.year:
        period = selector.year
145
    pass
146

147 148 149 150
    team = ""
    if selector.id_teams:
        team = db.teams[selector.id_teams].team
    pass
151

152 153 154 155
    project = ""
    if selector.id_projects:
        project = db.projects[selector.id_projects].project
    pass
156

157 158 159 160
    if team and not project:
        project = team
    elif team and project:
        project = "%s / %s" % (team, project)
161
    pass
162

163 164 165 166 167 168 169 170 171 172
    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)))

173 174 175 176 177
    #
    # the DIV block, one for each grid
    #
    divlogs = id(cfg_logsStore)
    divstat = id(cfg_statStore)
178

179 180
    response.write(DIV(_id="grid-%s" % divstat))
    response.write(DIV(_id="grid-%s" % divlogs))
181

182 183 184 185 186
    #
    # the HTML page footer:  processing time of the request
    #
    delta = (datetime.now()-request.now).total_seconds()
    delta = T('Check and validate took %s seconds') % round(delta, 2)
187

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

193
    response.write(P(delta, _style="".join(style)))
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
    #
    # export python variables to the javascript
    #
    jsvars = ["cfgLogsStore = %s" % cfg_logsStore,
              "cfgStatStore = %s" % cfg_statStore,
              "fields = %s" % publications_fields,
              "trCategory = '%s'" % T('Category'),
              "trCollection = '%s'" % T('Collection'),
              "trDuplicate = '%s'" % T('Duplicate'),
              "trError = '%s'" % T('Error'),
              "trId = '%s'" % T('Id'),
              "trInvalid = '%s'" % T('Invalid'),
              "trProject = '%s'" % T('Project'),
              "trRecord = '%s'" % T('Record'),
              "trRecords = '%s'" % T('Records'),
              "trStatistics = '%s'" % T('Statistics'),
              "trStatusOK = '%s'" % T('Status OK'),
              "trTitle = '%s'" % T('Title'),
              "trUpdate = '%s'" % T('Update'),
              "trValidated = '%s'" % T('Validated'),
              "trYear = '%s'" % T('Year'),
              "urlRead = '%s'" % URL('publications', 'read'),
              "urlUpdate = '%s'" % URL('publications', 'update')]

    jsvars = "    var %s;" % ',\n'.join(jsvars)
    response.write(SCRIPT(jsvars), escape=False)
221

222 223
}}
<script type="text/javascript">
224

225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
    var gridLog,
        gridStat;

    /**
     * handler to instantiate the form allowing to modify a publication record.
     *
     * @param {Number} publicationId
     *
     */
    function onGridLogClick(publicationId) {

        var actionLoad,
            actionSubmit,
            formPanel,
            window;

        //
        // define actions
        //
        actionLoad = {
            url: urlRead,
            params: {
                id: publicationId
            }
        };

        actionSubmit = {
            success: function () {
                window.close();
            },
            failure: function (form, action) {
                Ext.Msg.alert('Update failed', action.result.msg);
            }
        };

        //
        // instantiate the form
        // load it with the selected record
        //
        formPanel =  Ext.create('Ext.form.Panel', {
            buttons: [{
                formBind: true,
                text: trUpdate,
                handler: function () {
                    var btn = this;
                    btn.up('form').submit(actionSubmit);
                }
            }],
            items: fields,
            url: urlUpdate,
            width: 420
        });

        formPanel.load(actionLoad);

        //
        // instantiate the window and show it
        //
        window = Ext.create('Ext.window.Window', {
            closeAction: 'destroy',
            items: formPanel,
            layout: 'fit',
            modal: true,
            plain: true,
            title: trRecord.concat(" ",publicationId.toString())
        });

        window.show();
    }

295
    /**
296 297 298 299 300 301 302 303 304 305
     * Renderer functions
     *
     * @param {Object} value
     * @param {Object} metadata
     * @param {Ext.data.Model} record
     * @param {Number} rowIndex
     * @param {Number} colIndex
     * @param {Ext.data.Store} store
     * @param {Ext.view.view} view
     *
306 307 308 309 310
     */
    function rTotal() {
        return 'Total';
    }

311
    //
312
    // instantiate the grid showing the statistics
313
    //
314
    gridStat = Ext.create('Ext.grid.Panel', {
315 316 317 318 319
        title: trStatistics,
        store: Ext.create('Ext.data.ArrayStore', cfgStatStore),
        columns: [
            {xtype: 'rownumberer'},
            {text: trProject, dataIndex: 'project', flex: 2, summaryRenderer: rTotal},
320 321
            {text: trRecords, dataIndex: 'records', flex: 1, summaryType: 'sum'},
            {text: trStatusOK, dataIndex: 'ok', flex: 1, summaryType: 'sum'},
322
            {text: trValidated, dataIndex: 'validated', flex: 1, summaryType: 'sum'},
323
            {text: trInvalid, dataIndex: 'error', flex: 1, summaryType: 'sum'}
324
        ],
LE GAC Renaud's avatar
LE GAC Renaud committed
325
        collapsible: true,
326 327 328 329 330 331
        forceFit: true,
        features: [{ftype:'summary'}],
        padding: "0 40 20 30",
        renderTo: 'grid-{{=divstat}}'
    });

332
    //
333 334 335
    // instantiate the grid showing the log for each publication.
    // the row are group per error and sorted by title.
    // double click on a row display the form to modify the publication record.
336
    //
337
    gridLog = Ext.create('Ext.grid.Panel', {
338 339 340 341 342 343
        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},
344 345 346 347
            {text: trDuplicate, dataIndex: 'ids', flex: 0.4},
            {text: trCategory, dataIndex: 'category', flex: 0.2},
            {text: trProject, dataIndex: 'project', flex: 0.5},
            {text: trYear, dataIndex: 'year', flex: 0.2}
348 349 350 351 352 353
        ],
        features: [
            {ftype:'grouping', groupHeaderTpl: '{name}', startCollapsed: true}
        ],
        forceFit: true,
        padding: "10 40 20 30",
354
        renderTo: 'grid-{{=divlogs}}'
355 356
    });

357
</script>