Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Dspace7 Angular
Manage
Activity
Members
Labels
Plan
Issues
42
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vtechworks
Dspace7 Angular
Commits
9ac04235
Commit
9ac04235
authored
6 years ago
by
Giuseppe Digilio
Browse files
Options
Downloads
Patches
Plain Diff
Removed nested subscriptions
parent
d441c167
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/app/submission/sections/upload/file/file.component.ts
+66
-68
66 additions, 68 deletions
src/app/submission/sections/upload/file/file.component.ts
with
66 additions
and
68 deletions
src/app/submission/sections/upload/file/file.component.ts
+
66
−
68
View file @
9ac04235
import
{
ChangeDetectorRef
,
Component
,
Input
,
OnChanges
,
OnInit
}
from
'
@angular/core
'
;
import
{
filter
,
first
}
from
'
rxjs/operators
'
;
import
{
filter
,
first
,
flatMap
}
from
'
rxjs/operators
'
;
import
{
DynamicFormControlModel
,
}
from
'
@ng-dynamic-forms/core
'
;
import
{
NgbModal
}
from
'
@ng-bootstrap/ng-bootstrap
'
;
...
...
@@ -40,7 +40,6 @@ export class UploadSectionFileComponent implements OnChanges, OnInit {
public
fileData
:
WorkspaceitemSectionUploadFileObject
;
public
formId
;
public
formState
;
public
readMode
;
public
formModel
:
DynamicFormControlModel
[];
...
...
@@ -111,74 +110,73 @@ export class UploadSectionFileComponent implements OnChanges, OnInit {
public
saveBitstreamData
(
event
)
{
event
.
preventDefault
();
this
.
subscriptions
.
push
(
this
.
formService
.
getFormData
(
this
.
formId
).
pipe
(
first
())
.
subscribe
((
formData
:
any
)
=>
{
Object
.
keys
((
formData
.
metadata
))
.
filter
((
key
)
=>
isNotEmpty
(
formData
.
metadata
[
key
]))
.
forEach
((
key
)
=>
{
const
metadataKey
=
key
.
replace
(
/_/g
,
'
.
'
);
const
path
=
`metadata/
${
metadataKey
}
`
;
this
.
operationsBuilder
.
add
(
this
.
pathCombiner
.
getPath
(
path
),
formData
.
metadata
[
key
],
true
);
});
const
accessConditionsToSave
=
[];
formData
.
accessConditions
.
filter
((
accessCondition
)
=>
isNotEmpty
(
accessCondition
))
.
forEach
((
accessCondition
)
=>
{
let
accessConditionOpt
;
this
.
availableAccessConditionOptions
.
filter
((
element
)
=>
isNotNull
(
accessCondition
.
name
)
&&
element
.
name
===
accessCondition
.
name
[
0
].
value
)
.
forEach
((
element
)
=>
accessConditionOpt
=
element
);
if
(
accessConditionOpt
)
{
if
(
accessConditionOpt
.
hasStartDate
!==
true
&&
accessConditionOpt
.
hasEndDate
!==
true
)
{
accessConditionOpt
=
deleteProperty
(
accessConditionOpt
,
'
hasStartDate
'
);
accessConditionOpt
=
deleteProperty
(
accessConditionOpt
,
'
hasEndDate
'
);
accessConditionsToSave
.
push
(
accessConditionOpt
);
}
else
{
accessConditionOpt
=
Object
.
assign
({},
accessCondition
);
accessConditionOpt
.
name
=
this
.
retrieveValueFromField
(
accessCondition
.
name
);
accessConditionOpt
.
groupUUID
=
this
.
retrieveValueFromField
(
accessCondition
.
groupUUID
);
if
(
accessCondition
.
startDate
)
{
const
startDate
=
this
.
retrieveValueFromField
(
accessCondition
.
startDate
);
accessConditionOpt
.
startDate
=
dateToGMTString
(
startDate
);
accessConditionOpt
=
deleteProperty
(
accessConditionOpt
,
'
endDate
'
);
}
if
(
accessCondition
.
endDate
)
{
const
endDate
=
this
.
retrieveValueFromField
(
accessCondition
.
endDate
);
accessConditionOpt
.
endDate
=
dateToGMTString
(
endDate
);
accessConditionOpt
=
deleteProperty
(
accessConditionOpt
,
'
startDate
'
);
}
accessConditionsToSave
.
push
(
accessConditionOpt
);
this
.
subscriptions
.
push
(
this
.
formService
.
getFormData
(
this
.
formId
).
pipe
(
first
(),
flatMap
((
formData
:
any
)
=>
{
Object
.
keys
((
formData
.
metadata
))
.
filter
((
key
)
=>
isNotEmpty
(
formData
.
metadata
[
key
]))
.
forEach
((
key
)
=>
{
const
metadataKey
=
key
.
replace
(
/_/g
,
'
.
'
);
const
path
=
`metadata/
${
metadataKey
}
`
;
this
.
operationsBuilder
.
add
(
this
.
pathCombiner
.
getPath
(
path
),
formData
.
metadata
[
key
],
true
);
});
const
accessConditionsToSave
=
[];
formData
.
accessConditions
.
filter
((
accessCondition
)
=>
isNotEmpty
(
accessCondition
))
.
forEach
((
accessCondition
)
=>
{
let
accessConditionOpt
;
this
.
availableAccessConditionOptions
.
filter
((
element
)
=>
isNotNull
(
accessCondition
.
name
)
&&
element
.
name
===
accessCondition
.
name
[
0
].
value
)
.
forEach
((
element
)
=>
accessConditionOpt
=
element
);
if
(
accessConditionOpt
)
{
if
(
accessConditionOpt
.
hasStartDate
!==
true
&&
accessConditionOpt
.
hasEndDate
!==
true
)
{
accessConditionOpt
=
deleteProperty
(
accessConditionOpt
,
'
hasStartDate
'
);
accessConditionOpt
=
deleteProperty
(
accessConditionOpt
,
'
hasEndDate
'
);
accessConditionsToSave
.
push
(
accessConditionOpt
);
}
else
{
accessConditionOpt
=
Object
.
assign
({},
accessCondition
);
accessConditionOpt
.
name
=
this
.
retrieveValueFromField
(
accessCondition
.
name
);
accessConditionOpt
.
groupUUID
=
this
.
retrieveValueFromField
(
accessCondition
.
groupUUID
);
if
(
accessCondition
.
startDate
)
{
const
startDate
=
this
.
retrieveValueFromField
(
accessCondition
.
startDate
);
accessConditionOpt
.
startDate
=
dateToGMTString
(
startDate
);
accessConditionOpt
=
deleteProperty
(
accessConditionOpt
,
'
endDate
'
);
}
if
(
accessCondition
.
endDate
)
{
const
endDate
=
this
.
retrieveValueFromField
(
accessCondition
.
endDate
);
accessConditionOpt
.
endDate
=
dateToGMTString
(
endDate
);
accessConditionOpt
=
deleteProperty
(
accessConditionOpt
,
'
startDate
'
);
}
accessConditionsToSave
.
push
(
accessConditionOpt
);
}
}
);
if
(
isNotEmpty
(
accessConditionsToSave
))
{
this
.
operationsBuilder
.
add
(
this
.
pathCombiner
.
getPath
(
'
accessConditions
'
),
accessConditionsToSave
,
true
);
}
this
.
operationsService
.
jsonPatchByResourceID
(
this
.
submiss
ionService
.
getSubmissionObjectLinkName
(),
this
.
submission
Id
,
this
.
pathCombiner
.
rootElement
,
this
.
pathCombiner
.
subR
ootElement
)
.
subscribe
((
result
:
SubmissionObject
[])
=>
{
Object
.
keys
((
result
[
0
].
sections
.
upload
as
WorkspaceitemSectionUploadObject
).
files
)
.
filter
((
key
)
=>
(
result
[
0
].
sections
.
upload
as
WorkspaceitemSectionUploadObject
).
files
[
key
].
uuid
===
this
.
fileId
)
.
forEach
((
key
)
=>
this
.
uploadService
.
updateFileData
(
this
.
submission
Id
,
this
.
sectionId
,
this
.
file
Id
,
(
result
[
0
].
sections
.
upload
as
WorkspaceitemSectionUploadObject
).
files
[
key
]));
this
.
switchMode
();
}
);
})
);
}
});
if
(
isNotEmpty
(
accessConditionsToSave
))
{
this
.
operationsBuilder
.
add
(
this
.
pathCombiner
.
getPath
(
'
accessConditions
'
),
accessConditionsToSave
,
true
);
}
return
this
.
operat
ion
s
Service
.
jsonPatchByResourceID
(
this
.
submission
Service
.
getSubmissionObjectLinkName
()
,
this
.
submissionId
,
this
.
pathCombiner
.
r
ootElement
,
this
.
pathCombiner
.
subRootElement
)
}
)
).
subscribe
((
result
:
SubmissionObject
[])
=>
{
Object
.
keys
((
result
[
0
].
sections
.
upload
as
WorkspaceitemSectionUploadObject
).
files
)
.
filter
((
key
)
=>
(
result
[
0
].
sections
.
upload
as
WorkspaceitemSectionUploadObject
).
files
[
key
].
uuid
===
this
.
file
Id
)
.
forEach
((
key
)
=>
this
.
uploadService
.
updateFileData
(
this
.
submission
Id
,
this
.
sectionId
,
this
.
fileId
,
(
result
[
0
].
sections
.
upload
as
WorkspaceitemSectionUploadObject
).
files
[
key
])
);
this
.
switchMode
();
})
);
}
private
retrieveValueFromField
(
field
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment