Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
5419c02a
Unverified
Commit
5419c02a
authored
Oct 01, 2018
by
Nicolas Widart
Committed by
GitHub
Oct 01, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #597 from mikemand/hotfix/media-selection-reactivity
Fix reactivity of the medias data
parents
c4b102a4
61b9641c
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
76 additions
and
60 deletions
+76
-60
MultipleMedia.vue
Modules/Media/Assets/js/components/MultipleMedia.vue
+16
-22
SingleMedia.vue
Modules/Media/Assets/js/components/SingleMedia.vue
+11
-17
MultipleFileSelector.js
Modules/Media/Assets/js/mixins/MultipleFileSelector.js
+19
-16
RandomString.js
Modules/Media/Assets/js/mixins/RandomString.js
+15
-0
SingleFileSelector.js
Modules/Media/Assets/js/mixins/SingleFileSelector.js
+15
-5
No files found.
Modules/Media/Assets/js/components/MultipleMedia.vue
View file @
5419c02a
<
template
>
<div>
<label
class=
"el-form-item__label"
>
{{
getFieldLabel
()
}}
</label>
<div
class=
"jsThumbnailImageWrapper jsSingleThumbnailWrapper"
v-if=
"hasSelectedMedia"
>
<div
class=
"jsThumbnailImageWrapper jsSingleThumbnailWrapper"
v-if=
"hasSelectedMedia"
>
<figure
v-for=
"media in this.selectedMedia"
:key=
"media.id"
>
<img
:src=
"media.small_thumb"
alt=
""
v-if=
"media.is_image"
/>
<i
:class=
"`fa $
{media.fa_icon}`" style="font-size: 60px;" v-if="! media.is_image">
</i>
...
...
@@ -15,7 +15,7 @@
</div>
<el-dialog
:visible
.
sync=
"dialogVisible"
fullscreen
width=
"75%"
:before-close=
"handleClose"
>
<media-list
single-modal
:event-name=
"this.eventName"
></media-list>
...
...
@@ -29,12 +29,14 @@
<
script
>
import
axios
from
'
axios
'
;
import
UploadZone
from
'
../../../../Media/Assets/js/components/UploadZone.vue
'
;
import
MediaList
from
'
../../../../Media/Assets/js/components/MediaList.vue
'
;
import
_
from
'
lodash
'
;
import
UploadZone
from
'
./UploadZone.vue
'
;
import
MediaList
from
'
./MediaList.vue
'
;
import
StringHelpers
from
'
../../../../Core/Assets/js/mixins/StringHelpers.vue
'
;
import
RandomString
from
'
../mixins/RandomString
'
;
export
default
{
mixins
:
[
StringHelpers
],
mixins
:
[
StringHelpers
,
RandomString
],
props
:
{
zone
:
{
type
:
String
,
required
:
true
},
entity
:
{
type
:
String
,
required
:
true
},
...
...
@@ -88,20 +90,12 @@
getFieldLabel
()
{
return
this
.
label
||
this
.
ucwords
(
this
.
zone
.
replace
(
'
_
'
,
'
'
));
},
makeId
()
{
let
text
=
''
;
const
possible
=
'
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
'
;
for
(
let
i
=
0
;
i
<
5
;
i
++
)
{
text
+=
possible
.
charAt
(
Math
.
floor
(
Math
.
random
()
*
possible
.
length
));
}
return
text
;
},
},
mounted
()
{
if
(
this
.
entityId
)
{
this
.
fetchMedia
();
}
this
.
eventName
=
`fileWasSelected
${
this
.
makeId
()}${
Math
.
floor
(
Math
.
random
()
*
999999
)}
`
;
this
.
eventName
=
`fileWasSelected
${
this
.
randomString
()}${
Math
.
floor
(
Math
.
random
()
*
999999
)}
`
;
this
.
$events
.
listen
(
this
.
eventName
,
(
mediaData
)
=>
{
if
(
_
.
find
(
this
.
selectedMedia
,
mediaData
)
===
undefined
)
{
...
...
@@ -114,7 +108,7 @@
};
</
script
>
<
style
>
.remove-media
{
.remove-media
{
position
:
absolute
;
top
:
5px
;
left
:
5px
;
...
...
Modules/Media/Assets/js/components/SingleMedia.vue
View file @
5419c02a
...
...
@@ -16,7 +16,7 @@
<el-dialog
:visible
.
sync=
"dialogVisible"
fullscreen
width=
"75%"
:before-close=
"handleClose"
>
<media-list
single-modal
:event-name=
"this.eventName"
></media-list>
...
...
@@ -30,12 +30,14 @@
<
script
>
import
axios
from
'
axios
'
;
import
_
from
'
lodash
'
;
import
UploadZone
from
'
./UploadZone.vue
'
;
import
MediaList
from
'
./MediaList.vue
'
;
import
StringHelpers
from
'
../../../../Core/Assets/js/mixins/StringHelpers.vue
'
;
import
RandomString
from
'
../mixins/RandomString
'
;
export
default
{
mixins
:
[
StringHelpers
],
mixins
:
[
StringHelpers
,
RandomString
],
props
:
{
zone
:
{
type
:
String
,
required
:
true
},
entity
:
{
type
:
String
,
required
:
true
},
...
...
@@ -87,20 +89,12 @@
getFieldLabel
()
{
return
this
.
label
||
this
.
ucwords
(
this
.
zone
.
replace
(
'
_
'
,
'
'
));
},
makeId
()
{
let
text
=
''
;
const
possible
=
'
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
'
;
for
(
let
i
=
0
;
i
<
5
;
i
++
)
{
text
+=
possible
.
charAt
(
Math
.
floor
(
Math
.
random
()
*
possible
.
length
));
}
return
text
;
},
},
mounted
()
{
if
(
this
.
entityId
)
{
this
.
fetchMedia
();
}
this
.
eventName
=
`fileWasSelected
${
this
.
makeId
()}${
Math
.
floor
(
Math
.
random
()
*
999999
)}
`
;
this
.
eventName
=
`fileWasSelected
${
this
.
randomString
()}${
Math
.
floor
(
Math
.
random
()
*
999999
)}
`
;
this
.
$events
.
listen
(
this
.
eventName
,
(
mediaData
)
=>
{
this
.
dialogVisible
=
false
;
...
...
Modules/Media/Assets/js/mixins/MultipleFileSelector.js
View file @
5419c02a
export
default
{
methods
:
{
selectMultipleFile
(
event
,
model
)
{
if
(
!
this
[
model
].
medias_multi
)
{
this
[
model
].
medias_multi
=
{}
;
if
(
typeof
this
[
model
].
medias_multi
===
'
undefined
'
)
{
this
.
$set
(
model
,
'
medias_multi
'
,
{})
;
}
if
(
!
this
[
model
].
medias_multi
[
event
.
zone
])
{
this
[
model
].
medias_multi
[
event
.
zone
]
=
{
files
:
[]
};
if
(
typeof
this
[
model
].
medias_multi
[
event
.
zone
]
===
'
undefined
'
)
{
this
.
$set
(
this
[
model
].
medias_multi
,
event
.
zone
,
{
files
:
[],
orders
:
''
});
}
if
(
event
.
id
!==
null
&&
event
.
id
!==
undefined
)
{
const
medias
=
new
Set
(
this
[
model
].
medias_multi
[
event
.
zone
].
files
);
medias
.
add
(
event
.
id
);
this
.
$set
(
this
[
model
].
medias_multi
[
event
.
zone
],
'
files
'
,
[...
medias
]);
}
this
[
model
].
medias_multi
[
event
.
zone
].
files
.
push
(
event
.
id
);
},
unselectFile
(
event
,
model
)
{
if
(
!
this
[
model
].
medias_multi
)
{
this
[
model
].
medias_multi
=
{};
}
if
(
!
this
[
model
].
medias_multi
[
event
.
zone
])
{
this
[
model
].
medias_multi
[
event
.
zone
]
=
{
files
:
[]
};
if
(
this
.
$refs
[
'
multiple-media
'
]
!==
undefined
&&
this
.
$refs
[
'
multiple-media
'
].
selectedMedia
!==
undefined
&&
!
_
.
isEmpty
(
this
.
$refs
[
'
multiple-media
'
].
selectedMedia
))
{
_
.
forEach
(
this
.
$refs
[
'
multiple-media
'
].
selectedMedia
,
(
file
,
key
)
=>
{
this
[
model
].
medias_multi
[
event
.
zone
].
files
.
push
(
file
.
id
);
});
if
(
event
.
id
!==
null
&&
event
.
id
!==
undefined
)
{
const
medias
=
new
Set
(
this
[
model
].
medias_multi
[
event
.
zone
].
files
);
medias
.
delete
(
event
.
id
);
this
.
$set
(
this
[
model
].
medias_multi
[
event
.
zone
],
'
files
'
,
[...
medias
]);
}
if
(
this
[
model
].
medias_multi
[
event
.
zone
].
files
.
length
===
0
)
{
this
.
$delete
(
this
[
model
].
medias_multi
,
event
.
zone
);
}
this
[
model
].
medias_multi
[
event
.
zone
].
files
=
_
.
reject
(
this
[
model
].
medias_multi
[
event
.
zone
].
files
,
media
=>
media
===
event
.
id
);
},
},
};
Modules/Media/Assets/js/mixins/RandomString.js
0 → 100644
View file @
5419c02a
export
default
{
methods
:
{
randomString
(
length
)
{
const
len
=
length
||
5
;
let
text
=
''
;
const
possible
=
'
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
'
;
for
(
let
i
=
0
;
i
<
len
;
i
++
)
{
text
+=
possible
.
charAt
(
Math
.
floor
(
Math
.
random
()
*
possible
.
length
));
}
return
text
;
},
},
};
Modules/Media/Assets/js/mixins/SingleFileSelector.js
View file @
5419c02a
export
default
{
methods
:
{
selectSingleFile
(
event
,
model
)
{
this
[
model
].
medias_single
=
_
.
merge
(
this
[
model
].
medias_single
,
{
[
event
.
zone
]:
event
.
id
,
});
},
if
(
typeof
this
[
model
].
medias_single
===
'
undefined
'
)
{
this
.
$set
(
this
[
model
],
'
medias_single
'
,
{});
}
if
(
typeof
this
[
model
].
medias_single
[
event
.
zone
]
===
'
undefined
'
)
{
this
.
$set
(
this
[
model
].
medias_single
,
event
.
zone
,
null
);
}
if
(
event
.
id
!==
null
&&
event
.
id
!==
undefined
)
{
this
.
$set
(
this
[
model
].
medias_single
,
event
.
zone
,
event
.
id
);
}
else
{
this
.
$delete
(
this
[
model
].
medias_single
,
event
.
zone
);
}
}
},
},
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment