check_validate.html 11.2 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
LE GAC Renaud's avatar
LE GAC Renaud committed
25
    from plugin_dbui import JSONEncoder
26

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    #
    # 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:
48 49
            origin = origin.split(",")
            origin = origin[0].strip()
50 51 52 53 54 55 56 57 58
            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:
59
        script = "javascript:Limbra.onGridLogClick(%i)" % row.id
60 61 62
        row.id = str(A(row.id, _href=script))
    pass

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

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

    for project in counters:
        counter = counters[project]
        error = counter.found - counter.ok - counter.validated
78 79 80 81 82 83
        record = [counter.found,
                  counter.ok,
                  project,
                  counter.validated,
                  error]
        cfg['data'].append(record)
84 85
    pass

LE GAC Renaud's avatar
LE GAC Renaud committed
86
    cfg_statStore =  json.dumps(cfg, cls=JSONEncoder)
87

88
    #.........................................................................
89
    #
90
    # configure the Ext.data.Array for the logs
91
    #
92 93
    cfg = dict(data=[],
               groupField='txt',
94 95 96
               sorters=['txt', 'title'])

    cfg['fields'] = [{'name': 'category', 'type': 'string'},
97
                     {'name': 'id', 'type': 'string'},
98 99 100 101 102 103 104
                     {'name': 'ids', 'type': 'string'},
                     {'name': 'project', 'type': 'string'},
                     {'name': 'title', 'type': 'string'},
                     {'name': 'txt', 'type': 'string'},
                     {'name': 'year', 'type': 'int'}]

    for row in logs:
105
        for txt in row.txt:
106 107 108 109 110 111 112 113
            record = [row.category,
                      row.id,
                      ','.join(row.ids),
                      row.project,
                      row.title,
                      txt,
                      row.year]
            cfg['data'].append(record)
114
        pass
115
    pass
116

LE GAC Renaud's avatar
LE GAC Renaud committed
117
    cfg_logsStore =  json.dumps(cfg, cls=JSONEncoder)
118

119
    #.........................................................................
120
    #
121
    # configure the field name for the Ext.form.Panel
122
    #
123
    # HACK:
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
    # 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

LE GAC Renaud's avatar
LE GAC Renaud committed
144
    publications_fields = json.dumps(items, cls=JSONEncoder)
145

146
    #.........................................................................
147
    #
148
    # the title of the HTML page
149 150 151 152
    #
    period = ""
    if selector.year:
        period = selector.year
153
    pass
154

155 156 157 158
    team = ""
    if selector.id_teams:
        team = db.teams[selector.id_teams].team
    pass
159

160 161 162 163
    project = ""
    if selector.id_projects:
        project = db.projects[selector.id_projects].project
    pass
164

165 166 167 168
    if team and not project:
        project = team
    elif team and project:
        project = "%s / %s" % (team, project)
169
    pass
170

171 172 173 174 175 176 177 178 179 180
    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)))

181
    #.........................................................................
182 183 184
    #
    # the DIV block, one for each grid
    #
185 186
    divlogs = "grid-%s" % id(cfg_logsStore)
    divstat = "grid-%s" % id(cfg_statStore)
187

188 189
    response.write(DIV(_id=divstat))
    response.write(DIV(_id=divlogs))
190

191
    #.........................................................................
192 193 194 195 196
    #
    # 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)
197

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

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

205 206
}}
<script type="text/javascript">
207

208 209 210 211 212 213
    /**
     * handler to instantiate the form allowing to modify a publication record.
     *
     * @param {Number} publicationId
     *
     */
214
    Limbra.onGridLogClick = function (publicationId) {
215 216 217 218 219 220 221 222 223 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

        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,
255
            width: 450
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
        });

        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();
    }

275
    /**
276 277 278 279 280 281 282 283 284 285
     * 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
     *
286 287 288 289 290
     */
    function rTotal() {
        return 'Total';
    }

291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
    var cfgLogsStore = {{=XML(cfg_logsStore)}},
        cfgStatStore = {{=XML(cfg_statStore)}},
        fields = {{=XML(publications_fields)}},
        trCategory = '{{=T("Category")}}',
        trCollection = '{{=T("Collection")}}',
        trDuplicate = '{{=T("Duplicate")}}',
        trError = '{{=T("Error")}}',
        trId = '{{=T("Id")}}',
        trInvalid = '{{=T("Invalid")}}',
        trProject = '{{=T("Project")}}',
        trRecord = '{{=T("Record")}}',
        trRecords = '{{=T("Records")}}',
        trStatistics = '{{=T("Statistics")}}',
        trStatusOK = '{{=T("Status OK")}}',
        trTitle = '{{=T("Title")}}',
        trUpdate = '{{=T("Update")}}',
        trValidated = '{{=T("Validated")}}',
        trYear = '{{=T("Year")}}',
        urlRead = '{{=URL("publications", "read")}}',
        urlUpdate = '{{=URL("publications", "update")}}',
        gridLog, gridStat;

313
    //
314
    // instantiate the grid showing the statistics
315
    //
316
    gridStat = Ext.create('Ext.grid.Panel', {
317 318 319
        title: trStatistics,
        store: Ext.create('Ext.data.ArrayStore', cfgStatStore),
        columns: [
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
            {
                xtype: 'rownumberer'
            }, {
                text: trProject,
                dataIndex: 'project',
                flex: 2,
                summaryRenderer: rTotal
            }, {
                text: trRecords,
                dataIndex: 'records',
                flex: 1,
                summaryType: 'sum'
            }, {
                text: trStatusOK,
                dataIndex: 'ok',
                flex: 1,
                summaryType: 'sum'
            }, {
                text: trValidated,
                dataIndex: 'validated',
                flex: 1,
                summaryType: 'sum'
            }, {
                text: trInvalid,
                dataIndex: 'error',
                flex: 1,
                summaryType: 'sum'
            }
348
        ],
LE GAC Renaud's avatar
LE GAC Renaud committed
349
        collapsible: true,
350 351 352
        forceFit: true,
        features: [{ftype:'summary'}],
        padding: "0 40 20 30",
353
        renderTo: '{{=divstat}}'
354 355
    });

356
    //
357
    // instantiate the grid showing the log for each publication.
358
    //
359
    gridLog = Ext.create('Ext.grid.Panel', {
360 361 362 363
        store: Ext.create('Ext.data.ArrayStore', cfgLogsStore),
        columns: [
            {xtype: 'rownumberer'},
            {text: trTitle, dataIndex: 'title', flex: 3},
364
            {text: trError, dataIndex: 'txt', hidden: true},
365
            {text: trId, dataIndex: 'id', flex: 0.2},
366 367 368 369
            {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}
370 371 372 373 374 375
        ],
        features: [
            {ftype:'grouping', groupHeaderTpl: '{name}', startCollapsed: true}
        ],
        forceFit: true,
        padding: "10 40 20 30",
376
        renderTo: '{{=divlogs}}'
377 378
    });

379
</script>