View | Details | Raw Unified | Return to bug 40906
Collapse All | Expand All

(-)a/Koha/REST/V1/Mana/Reports.pm (+66 lines)
Line 0 Link Here
1
2
package Koha::REST::V1::Mana::Reports;
3
4
# This file is part of Koha.
5
#
6
# Koha is free software; you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# Koha is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with Koha; if not, see <https://www.gnu.org/licenses>.
18
19
use Modern::Perl;
20
21
use Mojo::Base 'Mojolicious::Controller';
22
23
use Try::Tiny qw( catch try );
24
25
use Koha::SharedContent;
26
27
=head1 API
28
29
=head2 Methods
30
31
=head3 list
32
33
=cut
34
35
sub list {
36
    my $c = shift->openapi->valid_input or return;
37
38
    my $per_page = $c->param('_per_page');
39
    my $page     = $c->param('_page');
40
    my $orderby  = $c->param('_order_by');
41
42
    my $query = $c->param('q');
43
44
    my $params = {
45
        per_page => $per_page,
46
        page     => $page,
47
        orderby  => $orderby
48
    };
49
50
    if ($query) {
51
        $params->{query} = $query;
52
    }
53
54
    my $result = Koha::SharedContent::search_entities( 'report', $params );
55
    if ( $result->{pagination} ) {
56
        $c->res->headers->header( "x-total-count" => $result->{pagination}->{total} );
57
    }
58
59
    return try {
60
        return $c->render( status => 200, openapi => $result->{data} );
61
    } catch {
62
        $c->unhandled_exception($_);
63
    };
64
}
65
66
1;
(-)a/api/v1/swagger/definitions/mana_comment.yaml (+27 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  id:
5
    description: The id of the comment in the mana debit
6
    type: integer 
7
  resource_id:
8
    description: The id of the resource in mana the comment is linked to
9
    type: integer
10
  resource_type:
11
    description: The type of resource the comment is attached to 
12
    type: string
13
  message:
14
    description: The content of the comment
15
    type: string
16
  creationdate:
17
    description: date of creation
18
    type: string
19
    format: date
20
21
22
  
23
  
24
  
25
26
additionalProperties: false
27
(-)a/api/v1/swagger/definitions/mana_report.yaml (+63 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  id:
5
    type: integer
6
    description: report id in mana
7
    readOnly: true
8
  report_name:
9
    description: The name of the report
10
    type: string
11
  notes:
12
    description: A description of the report
13
    type: 
14
      - string
15
      - "null"
16
  lastimport:
17
    description: The last time the report was imported from mana
18
    format: date
19
    type:
20
      - string
21
      - "null"
22
  creationdate:
23
    description: The day the report was exported to mana
24
    type: string
25
    format: date
26
  savedsql:
27
    description: The sql of the report
28
    type:
29
      - string
30
  language:
31
    description: The language the sql report has
32
    type:
33
      - string
34
      - "null"
35
  report_group: 
36
    description: The report group the report belongs to
37
    type:
38
      - string
39
      - "null"
40
  kohaversion: 
41
    description: The version of Koha from which the report was exported to mana
42
    type: 
43
      - string
44
      - "null"
45
  nbofusers: 
46
    description: The number of import of a report 
47
    type: 
48
      - integer
49
  # Do not leave as is ! 
50
  type: 
51
    description: Type
52
    type: 
53
      - string
54
      - "null" 
55
  comments: 
56
    description: Comments added by users to the reports
57
    type: 
58
      - array
59
    items: 
60
      $ref: "../swagger.yaml#/definitions/mana_comment"
61
62
additionalProperties: false
63
(-)a/api/v1/swagger/paths/mana.yaml (+50 lines)
Line 0 Link Here
1
---
2
/mana/reports:
3
  get:
4
    x-mojo-to: Mana::Reports#list
5
    operationId: searchReports
6
    tags:
7
      - mana 
8
      - reports
9
    summary: List reports registered in the mana database 
10
    produces:
11
      - application/json
12
    parameters:
13
      - $ref: "../swagger.yaml#/parameters/match"
14
      - $ref: "../swagger.yaml#/parameters/order_by"
15
      - $ref: "../swagger.yaml#/parameters/page"
16
      - $ref: "../swagger.yaml#/parameters/per_page"
17
      - $ref: "../swagger.yaml#/parameters/q_str"
18
      - $ref: "../swagger.yaml#/parameters/request_id_header"
19
    responses:
20
      "200":
21
        description: A List of reports
22
        schema:
23
          type: array
24
          items:
25
            $ref: "../swagger.yaml#/definitions/mana_report"
26
      "400":
27
        description: |
28
          Bad request. Possible `error_code` attribute values:
29
30
            * `invalid_query`
31
        schema:
32
          $ref: "../swagger.yaml#/definitions/error"
33
      "403":
34
        description: Access forbidden
35
        schema:
36
          $ref: "../swagger.yaml#/definitions/error"
37
      "500":
38
        description: |
39
          Internal server error. Possible `error_code` attribute values:
40
41
          * `internal_server_error`
42
        schema:
43
          $ref: "../swagger.yaml#/definitions/error"
44
      "503":
45
        description: Under maintenance
46
        schema:
47
          $ref: "../swagger.yaml#/definitions/error"
48
    x-koha-authorization:
49
      permissions:
50
        catalogue: "1"
(-)a/api/v1/swagger/swagger.yaml (+12 lines)
Lines 140-145 definitions: Link Here
140
    $ref: ./definitions/library.yaml
140
    $ref: ./definitions/library.yaml
141
  list:
141
  list:
142
    $ref: ./definitions/list.yaml
142
    $ref: ./definitions/list.yaml
143
  mana_comment: 
144
    $ref: ./definitions/mana_comment.yaml
145
  mana_report:
146
    $ref: ./definitions/mana_report.yaml
143
  merge_biblios:
147
  merge_biblios:
144
    $ref: ./definitions/merge_biblios.yaml
148
    $ref: ./definitions/merge_biblios.yaml
145
  order:
149
  order:
Lines 483-488 paths: Link Here
483
    $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}~1cash_registers"
487
    $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}~1cash_registers"
484
  "/libraries/{library_id}/desks":
488
  "/libraries/{library_id}/desks":
485
    $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}~1desks"
489
    $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}~1desks"
490
  "/mana/reports":
491
    $ref: "./paths/mana.yaml#/~1mana~1reports"
486
  "/oauth/login/{provider_code}/{interface}":
492
  "/oauth/login/{provider_code}/{interface}":
487
    $ref: ./paths/oauth.yaml#/~1oauth~1login~1{provider_code}~1{interface}
493
    $ref: ./paths/oauth.yaml#/~1oauth~1login~1{provider_code}~1{interface}
488
  /oauth/token:
494
  /oauth/token:
Lines 965-970 parameters: Link Here
965
    items:
971
    items:
966
      type: string
972
      type: string
967
    collectionFormat: multi
973
    collectionFormat: multi
974
  q_str: 
975
    description: Query string sent as a request parameter
976
    in: query
977
    name: q
978
    required: false
979
    type: string
968
  quote_id_pp:
980
  quote_id_pp:
969
    description: Quote internal identifier
981
    description: Quote internal identifier
970
    in: path
982
    in: path
(-)a/koha-tmpl/intranet-tmpl/prog/css/reports.css (+87 lines)
Lines 21-26 del { Link Here
21
    background-color: #ffe6e6;
21
    background-color: #ffe6e6;
22
}
22
}
23
23
24
#mana_results_datatable tbody { 
25
    display:flex;
26
    flex-wrap: wrap;
27
    justify-content: center;
28
}
29
30
#mana-search-result-modal-body {
31
    height: 80vh;
32
}
33
34
#overlay-report-details {
35
    display: none;
36
}
37
38
#overlay-report-details .CodeMirror {
39
    height: auto;
40
}
41
42
.return-div {
43
    font-size: 13px;
44
    cursor: pointer;
45
}
46
47
#mana_results_datatable td{
48
    width: 100%; 
49
    display: inline-block;
50
    border: none;
51
    background-color: transparent;
52
    text-align: left;
53
}
54
55
#mana_results_datatable tr {
56
    display: flex;
57
    flex-wrap: wrap;
58
    justify-content: space-between;
59
    clear:both;
60
    text-align:left;
61
    width: 19rem;
62
    padding: 0.25rem;
63
    margin: 0.25rem;
64
    background-color: #E6E6E6;
65
    border: none;
66
    border-radius: 0.25rem;
67
    margin-top: 1rem;
68
    font-size: 11px;
69
    height: 14rem;
70
}
71
72
#mana_results_datatable tr:hover {
73
    cursor: pointer;
74
}
75
76
.report_name {
77
    height: 3rem;
78
    font-weight: bold;
79
}
80
81
82
83
.mana-report-comments {
84
    padding: 1rem;
85
    margin: 4px;
86
    background-color: #E6E6E6;
87
    border: none;
88
    display: flex;
89
    align-items: center;
90
    justify-content: space-between;
91
}
92
93
.report-description {
94
    height:5rem; 
95
}
96
97
#mana_results_datatable .w-40 {
98
    width: 40%;
99
}
100
101
.report_info {
102
    color: #696969;    
103
    text-align: right;
104
    margin: 0 5px;
105
}
106
107
#mana_results_datatable .text-end {
108
    text-align: right;
109
}
110
24
#col1,
111
#col1,
25
#col2 {
112
#col2 {
26
    float: left;
113
    float: left;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-report-search-result.inc (-130 lines)
Lines 1-130 Link Here
1
[% USE Asset %]
2
[% USE KohaDates %]
3
[% USE Koha %]
4
[% USE AuthorisedValues %]
5
[% USE Branches %]
6
[% USE raw %]
7
[% PROCESS 'i18n.inc' %]
8
[% INCLUDE 'doc-head-open.inc' %]
9
<title
10
    >[% FILTER collapse %]
11
        [% t("Mana Knowledge Base reports search") | html %]
12
        &rsaquo; [% t("Reports") | html %] &rsaquo; [% t("Koha") | html %]
13
    [% END %]</title
14
>
15
[% INCLUDE 'doc-head-close.inc' %]
16
[% Asset.css("css/reports.css") | $raw %]
17
</head>
18
19
<body id="rep_mana_search" class="rep">
20
[% WRAPPER 'header.inc' %]
21
    [% INCLUDE 'circ-search.inc' %]
22
[% END %]
23
24
<div id="breadcrumbs">
25
    <a href="/cgi-bin/koha/mainpage.pl">Home</a>
26
    &rsaquo; <a href="/cgi-bin/koha/reports/reports-home.pl">Reports</a> &rsaquo; <a href="/cgi-bin/koha/reports/guided_reports.pl">Guided reports wizard</a>
27
    &rsaquo; Mana Knowledge Base report search results
28
</div>
29
30
<div class="main container-fluid">
31
    <div class="row">
32
        <div class="col-md-10 order-md-2 order-sm-1">
33
            <main>
34
                <h2>Mana Knowledge Base report search results</h2>
35
36
                <div id="mana_results">
37
                    [% IF statuscode == "200" AND reports %]
38
                        <table id="mana_results_datatable">
39
                            <thead>
40
                                <tr>
41
                                    <th>Report name</th>
42
                                    <th class="anti-the">Notes</th>
43
                                    <th>Type</th>
44
                                    <th title="Number of libraries using this pattern"># of users</th>
45
                                    <th title="Last time a library used this pattern">Last import</th>
46
                                    <th> Comments </th>
47
                                    [% UNLESS search_only %]
48
                                        <th class="no-sort no-export">Actions</th>
49
                                    [% END %]
50
                                </tr>
51
                            </thead>
52
                            <tbody>
53
                                [% FOREACH report IN reports %]
54
                                    [% UNLESS report.cannotdisplay %]
55
                                        [% IF report.nbofcomment > highWarned %]
56
                                            [% SET tr_class = 'high-warned-row' %]
57
                                        [% ELSIF report.nbofcomment > warned %]
58
                                            [% SET tr_class = 'warned-row' %]
59
                                        [% ELSIF report.nbofcomment > lowWarned %]
60
                                            [% SET tr_class = 'highlighted-row' %]
61
                                        [% ELSE %]
62
                                            [% SET tr_class = '' %]
63
                                        [% END %]
64
                                        <tr id="[% report.id | html %]" class="[% tr_class | html %]">
65
                                            <td>
66
                                                <input type="hidden" class="rowid" value="[% report.id | $raw %]" />
67
                                                [% IF ( report.report_name ) %]
68
                                                    [% report.report_name | html %]
69
                                                [% END %]
70
                                            </td>
71
                                            <td title="[% report.savedsql | html %]">
72
                                                [% IF report.notes.length > 200 %]
73
                                                    <div>
74
                                                        [% report.notes.substr(0,200) | html %]... <a href="#" class="btn btn-link btn-sm showbutton"><i class="fa-solid fa-square-plus"></i> Show more</a>
75
                                                    </div>
76
                                                    <div style="display:none">
77
                                                        [% report.notes | html %]
78
                                                        <a href="#" class="btn btn-link btn-sm hidebutton"><i class="fa-solid fa-square-minus"></i> Show less</a>
79
                                                    </div>
80
                                                [% ELSE %]
81
                                                    [% report.notes | html %]
82
                                                [% END %]
83
                                            </td>
84
                                            <td> [% report.type | html %] </td>
85
                                            <td>
86
                                                [% IF ( report.nbofusers ) %]
87
                                                    [% report.nbofusers | html %]
88
                                                [% END %]
89
                                            </td>
90
                                            <td data-order="[% report.lastimport | html %]"> [% report.lastimport | $KohaDates %] </td>
91
                                            <td>
92
                                                [% FOREACH comment IN report.comments %]
93
                                                    [% comment.message | html %]
94
                                                    ([% comment.nb | html %])<br />
95
                                                [% END %]
96
                                            </td>
97
98
                                            [% UNLESS search_only %]
99
                                                <td>
100
                                                    <button type="button" class="btn btn-default btn-xs mana-use" id="mana-use-[% report.id | html %]" data-report_id="[% report.id | html %]"><i class="fa fa-download"></i> Import</button>
101
                                                </td>
102
                                            [% END %]
103
                                        </tr>
104
                                    [% END %]
105
                                [% END %]
106
                            </tbody>
107
                        </table>
108
                    [% ELSE %]
109
                        <h4>
110
                            [% IF ( msg ) %]
111
                                [% msg | html %] <span>(Status code: [% statuscode | html %])</span>
112
                            [% ELSE %]
113
                                <span>No results found</span>
114
                            [% END %]
115
                        </h4>
116
                    [% END %]
117
                </div>
118
            </main>
119
        </div>
120
        <!-- /.col-md-10.order-md-2 -->
121
122
        <div class="col-md-2 order-sm-2 order-md-1">
123
            <aside> [% INCLUDE 'guided-reports-view.inc' %] </aside>
124
        </div>
125
        <!-- /.col-md-2.order-md-1 -->
126
    </div>
127
    <!-- /.row -->
128
129
    [% INCLUDE 'intranet-bottom.inc' %]
130
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc (-12 / +20 lines)
Lines 186-199 Link Here
186
186
187
[% IF Koha.Preference('Mana')==1 %]
187
[% IF Koha.Preference('Mana')==1 %]
188
    <div id="mana_search_result" class="modal" tabindex="-1" role="dialog" aria-labelledby="mana_search_result_label">
188
    <div id="mana_search_result" class="modal" tabindex="-1" role="dialog" aria-labelledby="mana_search_result_label">
189
        <div class="modal-dialog modal-lg">
189
        <div class="modal-dialog modal-xl">
190
            <form method="get" id="mana_search_form">
190
            <form method="get" id="mana_search_form">
191
                <div class="modal-content">
191
                <div class="modal-content" style="position:relative;">
192
                    <div class="modal-header">
192
                    <div class="modal-header">
193
                        <h1 class="modal-title" id="mana_search_result_label">Mana search</h1>
193
                        <h1 class="modal-title" id="mana_search_result_label">Mana search</h1>
194
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
194
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
195
                    </div>
195
                    </div>
196
                    <div class="modal-body">
196
                    <div id="mana-search-result-modal-body" class="modal-body">
197
                        <div id="overlay-report-details" class="modal-body"></div>
197
                        <div id="mana_search_failed" class="alert alert-warning mana_search_status" style="display:none">
198
                        <div id="mana_search_failed" class="alert alert-warning mana_search_status" style="display:none">
198
                            Your search could not be completed. Please try again later.
199
                            Your search could not be completed. Please try again later.
199
                            <div id="mana_search_errortext"></div>
200
                            <div id="mana_search_errortext"></div>
Lines 202-222 Link Here
202
                            This report could not be imported. Please try again later.
203
                            This report could not be imported. Please try again later.
203
                            <div id="mana_use_errortext"></div>
204
                            <div id="mana_use_errortext"></div>
204
                        </div>
205
                        </div>
205
                        <fieldset>
206
                        <div id="mana_results_datatable">
206
                            <p>
207
                            <table id="mana_result_content"></table>
207
                                Search reports by keyword:
208
                        </div>
208
                                <input type="text" id="mana_search_field" />
209
                                <input type="submit" class="mana_search_button" value="Search" />
210
                                <span id="mana-loading" style="display:none"> <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading </span>
211
                            </p>
212
                        </fieldset>
213
                        <div id="mana_result_content"> </div>
214
                    </div>
209
                    </div>
215
                    <div class="modal-footer">
210
                    <div class="modal-footer">
216
                        <button type="button" class="btn btn-default" data-bs-dismiss="modal">Cancel</button>
211
                        <button type="button" class="btn btn-default" data-bs-dismiss="modal">Cancel</button>
217
                    </div>
212
                    </div>
218
                </div>
213
                </div>
219
            </form>
214
            </form>
215
            <template id="report-details-template">
216
                <td class="report_name">
217
                    <span class="font-weight-bold"></span>
218
                </td>
219
                <td  class="report-description"> </td>
220
                <td class="w-40 report_info">
221
                    <i class="fa fa-cloud-arrow-down"></i>  
222
                </td>
223
                <td class="w-40 report_info text-end ms-auto" data-order="">  </td>
224
                <td>
225
                    <button type="button" class="btn btn-default btn-xs mana-use w-100"  data-report_id=""><i class="fa fa-download"></i> Import</button>
226
                </td>
227
            </template>
220
        </div>
228
        </div>
221
    </div>
229
    </div>
222
[% END %]
230
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/mana/mana-report-details.tt (+28 lines)
Line 0 Link Here
1
[% USE KohaDates %]
2
3
<div class="return-div"><i class="fa-regular fa-arrow-left"></i> Return to market place</div>
4
<hr />
5
<div class="p-3">
6
    <h1>[% title | html %]</h1>
7
8
    <p class="report_info"><i class="fa fa-cloud-arrow-down"></i> [% nbofusers %] </p>
9
    <p class="report_info">Created : [% lastimport | $KohaDates %]</p>
10
    <button type="button" class="btn btn-default btn-xs mana-use" id="mana-use-[% id | html %]" data-report_id="[% id | html %]"><i class="fa fa-download"></i> Import</button>
11
12
    <h3>SQL</h3>
13
    <textarea id="sql-mana" name="sql" required="required">[% savedsql | html %]</textarea>
14
15
    [% IF note %]
16
        <h3>Note</h3>
17
        <p>[% note | html %]</p>
18
    [% END %]
19
    [% IF comments %]
20
        <h3>Comments</h3>
21
        [% FOREACH comment IN comments %]
22
            <div class="mana-report-comments">
23
                <p>[% comment.message %]</p><p>[% comment.creationdate %]</p>
24
            </div>
25
        [% END %]
26
    [% END %]
27
28
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/mana/mana-report-search-result.tt (-1 lines)
Line 1 Link Here
1
[% INCLUDE 'mana/mana-report-search-result.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt (-51 lines)
Lines 2144-2153 Link Here
2144
                window.history.back();
2144
                window.history.back();
2145
            });
2145
            });
2146
2146
2147
            $("body").on("click", ".mana_search_button", function(){
2148
                $("#mana-loading").show();
2149
                mana_search($("#mana_search_field").val());
2150
            });
2151
2147
2152
            $(".ShareButton").on("click", function(){
2148
            $(".ShareButton").on("click", function(){
2153
                $("#note-error").hide();
2149
                $("#note-error").hide();
Lines 2443-2457 Link Here
2443
                mana_use( $(this).data("report_id") );
2439
                mana_use( $(this).data("report_id") );
2444
            });
2440
            });
2445
2441
2446
            $("#mana_search_result").on("shown.bs.modal", function(){
2447
                $("#mana_search_field").focus();
2448
            });
2449
2450
            $("#mana_search_result").on("hide.bs.modal", function(){
2451
                $("#mana_result_content").html("");
2452
                $("#mana_search_field").val("");
2453
            });
2454
2455
            $(".batch_op").on("click", function(e){
2442
            $(".batch_op").on("click", function(e){
2456
                e.preventDefault();
2443
                e.preventDefault();
2457
                var target_form = $(this).data("submit");
2444
                var target_form = $(this).data("submit");
Lines 2567-2610 Link Here
2567
            });
2554
            });
2568
        }
2555
        }
2569
2556
2570
        function mana_search( textquery ){
2571
            $(".mana_search_status").hide();
2572
            $("#mana_result_content").load("/cgi-bin/koha/svc/mana/search #mana_results", "resource=report&usecomments=1&id=" + textquery, function( response, status, xhr ) {
2573
2574
                    if ( status == "error" ) {
2575
                        $("#mana_search_errortext").html( xhr.status + " " + xhr.statusText );
2576
                        $("#mana_search_failed").show();
2577
                        $("#mana-loading").hide();
2578
                    } else {
2579
                        $(".mana_search_status").hide();
2580
                        $("#mana_search_result_label").text(_("Results from Mana Knowledge Base"));
2581
                        $("#mana-loading").hide();
2582
                        $("#mana_results_datatable").kohaTable({
2583
                            "pagingType": "full",
2584
                            "autoWidth": false,
2585
                            "columnDefs": [
2586
                                { "width": "35%", "targets": 1 }
2587
                            ],
2588
                        });
2589
2590
                        $(".showbutton").on("click", function(e){
2591
                            e.preventDefault();
2592
                            $(this).parent().hide();
2593
                            $(this).parent().next().show();
2594
                        });
2595
2596
                        $(".hidebutton").on("click", function(e){
2597
                            e.preventDefault();
2598
                            $(this).parent().hide();
2599
                            $(this).parent().prev().show();
2600
                        });
2601
2602
                        if($("td.dataTables_empty").length == 0){
2603
                            $("#mana_search_message").show();
2604
                        }
2605
                    }
2606
                });
2607
        }
2608
2557
2609
        function addToList() {
2558
        function addToList() {
2610
            var biblionumbers = [];
2559
            var biblionumbers = [];
(-)a/koha-tmpl/intranet-tmpl/prog/js/mana.js (+132 lines)
Lines 93-96 $(document).ready(function () { Link Here
93
            mana_increment(commentid, "resource_comment", "nb");
93
            mana_increment(commentid, "resource_comment", "nb");
94
        }
94
        }
95
    });
95
    });
96
97
    //Open mana report details
98
    $("body").on("click", "#mana_results_datatable tr", function (e) {
99
        let targeted_element = e.currentTarget;
100
101
        if (targeted_element.classList.contains("mana-use")) {
102
            return;
103
        }
104
105
        const id_ = targeted_element.id;
106
        let overlay_detail = $("#overlay-report-details")[0];
107
        overlay_detail.style.display = "block";
108
109
        let table = $("#mana_results_datatable")[0];
110
        table.style.display = "none";
111
112
        $.ajax({
113
            url: "/cgi-bin/koha/reports/mana_report_details.pl",
114
115
            data: {
116
                id: id_,
117
            },
118
            dataType: "html",
119
        }).done(function (data) {
120
            overlay_detail.innerHTML = data;
121
            let modal_body = $(".modal-body");
122
            let sql = $("#sql-mana")[0];
123
124
            modal_body.scrollTop(0);
125
126
            showsql = CodeMirror.fromTextArea(sql, {
127
                lineNumbers: false,
128
                mode: "text/x-sql",
129
                lineWrapping: true,
130
                readOnly: true,
131
            });
132
        });
133
134
        $("body").on("click", ".return-div", function (e) {
135
            let overlay_detail = $("#overlay-report-details")[0];
136
            overlay_detail.style.display = "none";
137
            overlay_detail.innerHTML = "";
138
139
            let table = $("#mana_results_datatable")[0];
140
            table.style.display = "block";
141
        });
142
143
        $("#mana_search_result")[0].addEventListener(
144
            "hidden.bs.modal",
145
            event => {
146
                let overlay_detail = $("#overlay-report-details")[0];
147
                overlay_detail.style.display = "none";
148
                overlay_detail.innerHTML = "";
149
150
                let table = $("#mana_results_datatable")[0];
151
                table.style.display = "block";
152
            }
153
        );
154
    });
155
156
    //Creates datatable
157
    $("#mana_search_result")[0].addEventListener("show.bs.modal", event => {
158
        if ($.fn.dataTable.isDataTable("#mana_result_content")) {
159
            return;
160
        }
161
162
        let table = $("#mana_result_content").kohaTable({
163
            autoWidth: false,
164
            fixedHeader: false,
165
            serverSide: true,
166
            ajax: {
167
                url: "/api/v1/mana/reports",
168
                data: function (data, setting) {
169
                    var length = data.length;
170
                    var start = data.start;
171
                    var dataSet = {
172
                        _page: Math.floor(start / length) + 1,
173
                        _per_page: length,
174
                        _order_by: "",
175
                    };
176
177
                    //This is why the kohaTables data function is overwritten, to allow passing the search query as a string.
178
                    if (data.search) {
179
                        dataSet.q = data.search.value;
180
                    }
181
                    return dataSet;
182
                },
183
            },
184
            createdRow: function (row, data, dataIndex) {
185
                let template = $("#report-details-template")[0];
186
                const clone = document.importNode(template.content, true);
187
                //changer id de la row
188
                const title = clone.querySelector("span");
189
                const description = clone.querySelectorAll("td")[1];
190
                const nbofuser_place = clone.querySelector(".report_info");
191
                const lastimport_place =
192
                    clone.querySelectorAll(".report_info")[1];
193
                const button = clone.querySelector("button");
194
195
                title.textContent = data.report_name;
196
                if (data.notes.length > 100) {
197
                    data.notes = data.notes.slice(0, 100) + "...";
198
                }
199
                description.textContent = data.notes;
200
201
                nbofuser_place.append(data.nbofusers);
202
                lastimport_place.textContent = data.lastimport;
203
                button.id = "mana-use-".concat(data.id);
204
                button.setAttribute("data-report_id", data.id);
205
206
                row.id = data.id;
207
                row.innerHTML = "";
208
                row.appendChild(clone);
209
            },
210
211
            columns: [
212
                { data: "id" },
213
                { data: "report_name" },
214
                { data: "notes" },
215
                { data: "nbofusers" },
216
                { data: "lastimport" },
217
            ],
218
        });
219
220
        let thead = $("#mana_results_datatable thead");
221
        thead.addClass("visually-hidden");
222
223
        table.on("draw", function () {
224
            let thead = $("#mana_results_datatable thead")[0];
225
            thead.addClass("visually-hidden");
226
        });
227
    });
96
});
228
});
(-)a/reports/mana_report_details.pl (+43 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Koha::SharedContent;
6
use C4::Auth qw(check_cookie_auth);
7
use Koha::Report;
8
9
use C4::Auth   qw(get_template_and_user);
10
use C4::Output qw( output_html_with_http_headers );
11
12
use CGI;
13
use JSON;
14
15
my $input = CGI->new;
16
17
my $templatename = 'mana/mana-report-details.tt';
18
19
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
20
    {
21
        template_name => $templatename,
22
        query         => $input,
23
        type          => 'intranet'
24
    }
25
);
26
27
my $result = Koha::SharedContent::get_entity_by_id(
28
    "report",
29
    scalar $input->param('id'),
30
    { usecomments => 1 }
31
);
32
33
$template->param(
34
    id         => $result->{data}->{id},
35
    title      => $result->{data}->{report_name},
36
    savedsql   => $result->{data}->{savedsql},
37
    note       => $result->{data}->{notes},
38
    nbofusers  => $result->{data}->{nbofusers},
39
    lastimport => $result->{data}->{lastimport},
40
    comments    => $result->{data}->{comments}
41
);
42
43
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/svc/mana/search (-6 / +1 lines)
Lines 30-40 use CGI; Link Here
30
my $input = CGI->new;
30
my $input = CGI->new;
31
31
32
my $templatename;
32
my $templatename;
33
if ( $input->param("resource") eq 'report' ) {
33
$templatename = "mana/mana-subscription-search-result.tt";
34
    $templatename = "mana/mana-report-search-result.tt";
35
} else {
36
    $templatename = "mana/mana-subscription-search-result.tt";
37
}
38
34
39
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
35
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
40
    {
36
    {
41
- 

Return to bug 40906