Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SMPPIR-CheckIn_API
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SMPPIR
SMPPIR-CheckIn_API
Merge requests
!1
Csv download
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Csv download
CSV_download
into
master
Overview
0
Commits
3
Pipelines
0
Changes
2
Merged
Henrique Varella Ehrenfried
requested to merge
CSV_download
into
master
4 years ago
Overview
0
Commits
3
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
24f16d41
3 commits,
4 years ago
2 files
+
123
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
common/models/category.js
+
49
−
0
Options
@@ -21,4 +21,53 @@ along with SMPPIR-CheckIn. If not, see <https://www.gnu.org/licenses/>.
'
use strict
'
;
module
.
exports
=
function
(
Category
)
{
Category
.
csvexport
=
function
(
res
,
callback
)
{
var
datetime
=
new
Date
();
var
datetimeFuture
=
new
Date
(
datetime
.
getFullYear
(),
datetime
.
getMonth
(),
datetime
.
getDate
()
+
7
)
res
.
set
(
'
Expires
'
,
datetimeFuture
+
''
);
res
.
set
(
'
Cache-Control
'
,
'
max-age=0, no-cache, must-revalidate, proxy-revalidate
'
);
res
.
set
(
'
Last-Modified
'
,
datetime
+
''
);
res
.
set
(
'
Content-Type
'
,
'
application/force-download
'
);
res
.
set
(
'
Content-Type
'
,
'
application/octet-stream
'
);
res
.
set
(
'
Content-Type
'
,
'
application/download
'
);
res
.
set
(
'
Content-Disposition
'
,
'
attachment;filename=category.csv
'
);
res
.
set
(
'
Content-Transfer-Encoding
'
,
'
binary
'
);
Category
.
find
(
function
(
err
,
categories
)
{
// conversão JSON para CSV
// cabeçalho do csv
var
headers
=
{
category_name
:
"
category_name
"
,
category_description
:
"
category_description
"
,
id
:
"
id
"
};
//Adiciona os headers no CSV
categories
.
unshift
(
headers
);
var
jsonObject
=
JSON
.
stringify
(
categories
);
var
array
=
typeof
jsonObject
!=
'
object
'
?
JSON
.
parse
(
jsonObject
)
:
jsonObject
;
var
csv
=
''
;
for
(
var
i
=
0
;
i
<
array
.
length
;
i
++
)
{
var
line
=
''
;
for
(
var
index
in
array
[
i
])
{
if
(
line
!=
''
)
line
+=
'
;
'
// aqui muda o separador do csv
line
+=
array
[
i
][
index
];
}
csv
+=
line
+
'
\n
'
;
}
res
.
send
(
csv
);
});
};
Category
.
remoteMethod
(
'
csvexport
'
,
{
accepts
:
[
{
arg
:
'
res
'
,
type
:
'
object
'
,
'
http
'
:
{
source
:
'
res
'
}}
],
returns
:
{},
http
:
{
path
:
'
/csv
'
,
verb
:
'
get
'
},
});
};
Loading