Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
edx
edx-platform
Commits
ba9242b3
Commit
ba9242b3
authored
Oct 31, 2016
by
Jillian Vogel
Committed by
GitHub
Oct 31, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12633 from tanmaykm/tanmaykm/video-upload
MA-333 Added ability to refresh uploaded videos
parents
c012bd6c
1bc1c545
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
120 additions
and
28 deletions
+120
-28
AUTHORS
+1
-0
cms/djangoapps/contentstore/views/videos.py
+1
-1
cms/static/js/factories/videos_index.js
+30
-10
cms/static/js/models/active_video_upload.js
+1
-0
cms/static/js/spec/views/active_video_upload_list_spec.js
+44
-15
cms/static/js/views/active_video_upload_list.js
+43
-2
No files found.
AUTHORS
View file @
ba9242b3
...
...
@@ -276,3 +276,4 @@ Kevin Kim <kkim@edx.org>
Albert St. Aubin Jr. <astaubin@edx.org>
Casey Litton <caseylitton@gmail.com>
Jhony Avella <jhony.avella@edunext.co>
Tanmay Mohapatra <tanmaykm@gmail.com>
cms/djangoapps/contentstore/views/videos.py
View file @
ba9242b3
...
...
@@ -336,7 +336,7 @@ def videos_post(course, request):
"courses"
:
[
course
.
id
]
})
resp_files
.
append
({
"file_name"
:
file_name
,
"upload_url"
:
upload_url
})
resp_files
.
append
({
"file_name"
:
file_name
,
"upload_url"
:
upload_url
,
"edx_video_id"
:
edx_video_id
})
return
JsonResponse
({
"files"
:
resp_files
},
status
=
200
)
...
...
cms/static/js/factories/videos_index.js
View file @
ba9242b3
define
(
[
'jquery'
,
'backbone'
,
'js/views/active_video_upload_list'
,
'js/views/previous_video_upload_list'
],
function
(
$
,
Backbone
,
ActiveVideoUploadListView
,
PreviousVideoUploadListView
)
{
define
([
'jquery'
,
'backbone'
,
'js/views/active_video_upload_list'
,
'js/views/previous_video_upload_list'
,
'js/views/active_video_upload'
],
function
(
$
,
Backbone
,
ActiveVideoUploadListView
,
PreviousVideoUploadListView
,
ActiveVideoUpload
)
{
'use strict'
;
var
VideosIndexFactory
=
function
(
$contentWrapper
,
...
...
@@ -13,17 +14,36 @@ define(
var
activeView
=
new
ActiveVideoUploadListView
({
postUrl
:
postUrl
,
concurrentUploadLimit
:
concurrentUploadLimit
,
uploadButton
:
uploadButton
uploadButton
:
uploadButton
,
onFileUploadDone
:
function
(
activeVideos
)
{
$
.
ajax
({
url
:
postUrl
,
contentType
:
'application/json'
,
dataType
:
'json'
,
type
:
'GET'
}).
done
(
function
(
responseData
)
{
var
updatedCollection
=
new
Backbone
.
Collection
(
responseData
.
videos
).
filter
(
function
(
video
)
{
// Include videos that are not in the active video upload list,
// or that are marked as Upload Complete
var
isActive
=
activeVideos
.
where
({
videoId
:
video
.
get
(
'edx_video_id'
)});
return
isActive
.
length
===
0
||
isActive
[
0
].
get
(
'status'
)
===
ActiveVideoUpload
.
STATUS_COMPLETE
;
}),
updatedView
=
new
PreviousVideoUploadListView
({
collection
:
updatedCollection
,
encodingsDownloadUrl
:
encodingsDownloadUrl
});
$contentWrapper
.
append
(
activeView
.
render
().
$el
);
var
previousCollection
=
new
Backbone
.
Collection
(
previousUploads
);
var
previousView
=
new
PreviousVideoUploadListView
({
collection
:
previousCollection
,
$contentWrapper
.
find
(
'.wrapper-assets'
).
replaceWith
(
updatedView
.
render
().
$el
);
});
}
}),
previousView
=
new
PreviousVideoUploadListView
({
collection
:
new
Backbone
.
Collection
(
previousUploads
),
encodingsDownloadUrl
:
encodingsDownloadUrl
});
$contentWrapper
.
append
(
activeView
.
render
().
$el
);
$contentWrapper
.
append
(
previousView
.
render
().
$el
);
};
return
VideosIndexFactory
;
}
);
});
cms/static/js/models/active_video_upload.js
View file @
ba9242b3
...
...
@@ -19,6 +19,7 @@ define(
var
ActiveVideoUpload
=
Backbone
.
Model
.
extend
(
{
defaults
:
{
videoId
:
null
,
status
:
statusStrings
.
STATUS_QUEUED
,
progress
:
0
}
...
...
cms/static/js/spec/views/active_video_upload_list_spec.js
View file @
ba9242b3
/* global _ */
define
(
[
'jquery'
,
...
...
@@ -174,42 +175,68 @@ define(
// 2.0, the latest version of jasmine-ajax (mock-ajax.js) does have the
// necessary support.
_
.
each
(
[
_
.
each
([
true
,
false
],
function
(
isViewRefresh
)
{
var
refreshDescription
=
isViewRefresh
?
' (refreshed)'
:
' (not refreshed)'
;
var
subCases
=
[
{
desc
:
'completion'
,
desc
:
'completion'
+
refreshDescription
,
responseStatus
:
204
,
statusText
:
ActiveVideoUpload
.
STATUS_COMPLETED
,
progressValue
:
1
,
presentClass
:
'success'
,
absentClass
:
'error'
absentClass
:
'error'
,
isViewRefresh
:
isViewRefresh
},
{
desc
:
'failure'
,
desc
:
'failure'
+
refreshDescription
,
responseStatus
:
500
,
statusText
:
ActiveVideoUpload
.
STATUS_FAILED
,
progressValue
:
0
,
presentClass
:
'error'
,
absentClass
:
'success'
absentClass
:
'success'
,
isViewRefresh
:
isViewRefresh
}
],
];
_
.
each
(
subCases
,
function
(
subCaseInfo
)
{
describe
(
'and upload '
+
subCaseInfo
.
desc
,
function
()
{
var
refreshSpy
=
null
;
beforeEach
(
function
()
{
getSentRequests
()[
0
].
respondWith
({
status
:
subCaseInfo
.
responseStatus
});
refreshSpy
=
subCaseInfo
.
isViewRefresh
?
jasmine
.
createSpy
()
:
null
;
this
.
view
.
onFileUploadDone
=
refreshSpy
;
getSentRequests
()[
0
].
respondWith
(
{
status
:
subCaseInfo
.
responseStatus
}
);
});
it
(
'should update status and progress'
,
function
()
{
var
$uploadElem
=
this
.
view
.
$
(
'.active-video-upload:first'
);
if
(
subCaseInfo
.
isViewRefresh
&&
subCaseInfo
.
responseStatus
===
204
)
{
expect
(
refreshSpy
).
toHaveBeenCalled
();
if
(
$uploadElem
.
length
>
0
)
{
expect
(
$
.
trim
(
$uploadElem
.
find
(
'.video-detail-status'
).
text
())
).
not
.
toEqual
(
ActiveVideoUpload
.
STATUS_COMPLETED
);
expect
(
$uploadElem
.
find
(
'.video-detail-progress'
).
val
()
).
not
.
toEqual
(
1
);
expect
(
$uploadElem
).
not
.
toHaveClass
(
'success'
);
}
}
else
{
expect
(
$uploadElem
.
length
).
toEqual
(
1
);
expect
(
$
.
trim
(
$uploadElem
.
find
(
'.video-detail-status'
).
text
())).
toEqual
(
subCaseInfo
.
statusText
);
expect
(
$
.
trim
(
$uploadElem
.
find
(
'.video-detail-status'
).
text
())
).
toEqual
(
subCaseInfo
.
statusText
);
expect
(
$uploadElem
.
find
(
'.video-detail-progress'
).
val
()
).
toEqual
(
subCaseInfo
.
progressValue
);
expect
(
$uploadElem
).
toHaveClass
(
subCaseInfo
.
presentClass
);
expect
(
$uploadElem
).
not
.
toHaveClass
(
subCaseInfo
.
absentClass
);
}
});
it
(
'should not trigger the global AJAX error handler'
,
function
()
{
...
...
@@ -218,13 +245,13 @@ define(
if
(
caseInfo
.
numFiles
>
concurrentUploadLimit
)
{
it
(
'should start a new upload'
,
function
()
{
var
$uploadElem
=
$
(
this
.
$uploadElems
[
concurrentUploadLimit
]);
expect
(
getSentRequests
().
length
).
toEqual
(
concurrentUploadLimit
+
1
);
var
$uploadElem
=
$
(
this
.
$uploadElems
[
concurrentUploadLimit
]);
expect
(
$
.
trim
(
$uploadElem
.
find
(
'.video-detail-status'
).
text
())).
toEqual
(
ActiveVideoUpload
.
STATUS_UPLOADING
);
expect
(
$
.
trim
(
$uploadElem
.
find
(
'.video-detail-status'
).
text
())
).
toEqual
(
ActiveVideoUpload
.
STATUS_UPLOADING
);
expect
(
$uploadElem
).
not
.
toHaveClass
(
'queued'
);
});
}
...
...
@@ -246,6 +273,8 @@ define(
});
}
);
}
);
});
});
}
...
...
cms/static/js/views/active_video_upload_list.js
View file @
ba9242b3
...
...
@@ -18,6 +18,7 @@ define(
this
.
listenTo
(
this
.
collection
,
'add'
,
this
.
addUpload
);
this
.
concurrentUploadLimit
=
options
.
concurrentUploadLimit
||
0
;
this
.
postUrl
=
options
.
postUrl
;
this
.
onFileUploadDone
=
options
.
onFileUploadDone
;
if
(
options
.
uploadButton
)
{
options
.
uploadButton
.
click
(
this
.
chooseFile
.
bind
(
this
));
}
...
...
@@ -99,9 +100,10 @@ define(
// individual file uploads, using the extra `redirected` field to
// indicate that the correct upload url has already been retrieved
fileUploadAdd
:
function
(
event
,
uploadData
)
{
var
view
=
this
;
var
view
=
this
,
model
;
if
(
uploadData
.
redirected
)
{
var
model
=
new
ActiveVideoUpload
({
fileName
:
uploadData
.
files
[
0
].
name
});
model
=
new
ActiveVideoUpload
({
fileName
:
uploadData
.
files
[
0
].
name
,
videoId
:
uploadData
.
videoId
});
this
.
collection
.
add
(
model
);
uploadData
.
cid
=
model
.
cid
;
uploadData
.
submit
();
...
...
@@ -126,6 +128,7 @@ define(
view
.
$uploadForm
.
fileupload
(
'add'
,
{
files
:
[
uploadData
.
files
[
index
]],
url
:
file
[
'upload_url'
],
videoId
:
file
.
edx_video_id
,
multipart
:
false
,
global
:
false
,
// Do not trigger global AJAX error handler
redirected
:
true
...
...
@@ -156,10 +159,48 @@ define(
fileUploadDone
:
function
(
event
,
data
)
{
this
.
setStatus
(
data
.
cid
,
ActiveVideoUpload
.
STATUS_COMPLETED
);
this
.
setProgress
(
data
.
cid
,
1
);
if
(
this
.
onFileUploadDone
)
{
this
.
onFileUploadDone
(
this
.
collection
);
this
.
clearSuccessful
();
}
},
fileUploadFail
:
function
(
event
,
data
)
{
this
.
setStatus
(
data
.
cid
,
ActiveVideoUpload
.
STATUS_FAILED
);
},
removeViewAt
:
function
(
index
)
{
this
.
itemViews
.
splice
(
index
);
this
.
$
(
'.active-video-upload-list li'
).
eq
(
index
).
remove
();
},
// Removes the upload progress view for files that have been
// uploaded successfully. Also removes the corresponding models
// from `collection`, keeping both in sync.
clearSuccessful
:
function
()
{
var
idx
,
completedIndexes
=
[],
completedModels
=
[],
completedMessages
=
[];
this
.
collection
.
each
(
function
(
model
,
index
)
{
if
(
model
.
get
(
'status'
)
===
ActiveVideoUpload
.
STATUS_COMPLETED
)
{
completedModels
.
push
(
model
);
completedIndexes
.
push
(
index
-
completedIndexes
.
length
);
completedMessages
.
push
(
model
.
get
(
'fileName'
)
+
gettext
(
': video upload complete.'
));
}
});
for
(
idx
=
0
;
idx
<
completedIndexes
.
length
;
idx
++
)
{
this
.
removeViewAt
(
completedIndexes
[
idx
]);
this
.
collection
.
remove
(
completedModels
[
idx
]);
}
// Alert screen readers that the uploads were successful
if
(
completedMessages
.
length
)
{
completedMessages
.
push
(
gettext
(
'Previous Uploads table has been updated.'
));
if
(
$
(
window
).
prop
(
'SR'
)
!==
undefined
)
{
$
(
window
).
prop
(
'SR'
).
readTexts
(
completedMessages
);
}
}
}
});
...
...
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