-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Collections #1810
Draft
quimmrc
wants to merge
31
commits into
master
Choose a base branch
from
collections
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Collections #1810
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
813bd48
collections app creation and first basic implementations
quimmrc 52543c4
migration: add collection attributes
quimmrc 5f137eb
attempt to implement collection modals
quimmrc 51adc61
models reformulation
quimmrc 13a90da
Merge branch 'master' into collections
quimmrc 2780959
add sound modal behavior tbd
quimmrc 4c7c190
add sound modal collection selector
quimmrc 0f47090
add sound to col from sound url
quimmrc fc55074
delete sound from collection func.
quimmrc b2e0277
deletion for CollectionSound + restrict add duplicates
quimmrc 5ba088d
minor details correction
quimmrc ae9950b
delete and create collection functionalities
quimmrc d679849
Edit collection permissions
quimmrc 58d845f
add collection parameter to settings.py
quimmrc 3d7a668
add maintainer modal (fails)
quimmrc 5ffea0b
add maintainers interface
quimmrc d5fed09
adequate variable namings for collection modals
quimmrc 04ba23d
maintainers display in edit collection url
quimmrc e2bc70a
Merge branch 'master' into collections
quimmrc 18c9548
changes from github review
quimmrc 034528c
Merge branch 'master' into collections
quimmrc f62d388
db update + review + collect sound small player
quimmrc 81affae
add sound to collection for all sound displays
quimmrc 79787d1
remove maintainers from edit page
quimmrc 82b3e2a
add maintainers
quimmrc d8fe151
Initial tests + create collections from scratch
quimmrc 058d326
enable bookmark collection + public/private edition
quimmrc 8fd039a
add sounds from small player + display Json success msg
quimmrc cd609e0
download collections
quimmrc f64d1b2
tests and miscellanious
quimmrc ff18e6b
order paginator query
quimmrc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
freesound/static/bw-frontend/src/components/collections.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import {dismissModal, handleGenericModal} from "./modal"; | ||
import {showToast} from "./toast"; | ||
import {makePostRequest} from "../utils/postRequest"; | ||
|
||
const saveCollectionSound = (collectionSoundUrl, data) => { | ||
|
||
let formData = {}; | ||
if (data === undefined){ | ||
formData.name = ""; | ||
formData.collection = ""; | ||
formData.new_collection_name = ""; | ||
formData.use_last_collection = true; | ||
} else { | ||
formData = data; | ||
} | ||
makePostRequest(collectionSoundUrl, formData, (responseText) => { | ||
// Collection attribute saved successfully. Close model and show feedback | ||
dismissModal('collectSoundModal'); // TBC | ||
try { | ||
showToast(JSON.parse(responseText).message); | ||
} catch (error) { | ||
// If not logged in, the url will respond with a redirect and JSON parsing will fail | ||
showToast("You need to be logged in before using collections.") | ||
} | ||
}, () => { | ||
// Unexpected errors happened while processing request: close modal and show error in toast | ||
dismissModal('collectSoundModal'); | ||
showToast('Some errors occurred while adding the sound to the collection.'); | ||
}); | ||
} | ||
|
||
|
||
const toggleNewCollectionNameDiv = (select, newCollectionNameDiv) => { | ||
if (select.value == '0'){ | ||
// No category is selected, show the new category name input | ||
newCollectionNameDiv.classList.remove('display-none'); | ||
} else { | ||
newCollectionNameDiv.classList.add('display-none'); | ||
} | ||
} | ||
|
||
|
||
const initCollectionFormModal = (soundId, collectionSoundUrl) => { | ||
|
||
// Modify the form structure to add a "Category" label inline with the select dropdown | ||
const modalContainer = document.getElementById('collectSoundModal'); | ||
const selectElement = modalContainer.getElementsByTagName('select')[0]; | ||
const wrapper = document.createElement('div'); | ||
wrapper.style = 'display:inline-block;'; | ||
if (selectElement === undefined){ | ||
// If no select element, the modal has probably loaded for an unauthenticated user | ||
return; | ||
} | ||
selectElement.parentNode.insertBefore(wrapper, selectElement.parentNode.firstChild); | ||
const label = document.createElement('div'); | ||
label.innerHTML = "Select a collection:" | ||
label.classList.add('text-grey'); | ||
wrapper.appendChild(label) | ||
wrapper.appendChild(selectElement) | ||
|
||
const formElement = modalContainer.getElementsByTagName('form')[0]; | ||
const buttonsInModalForm = formElement.getElementsByTagName('button'); | ||
const saveButtonElement = buttonsInModalForm[buttonsInModalForm.length - 1]; | ||
const categorySelectElement = document.getElementById(`id_${ soundId.toString() }-collection`); | ||
|
||
const newCategoryNameElement = document.getElementById(`id_${ soundId.toString() }-new_collection_name`); | ||
toggleNewCollectionNameDiv(categorySelectElement, newCategoryNameElement); | ||
categorySelectElement.addEventListener('change', (event) => { | ||
toggleNewCollectionNameDiv(categorySelectElement, newCategoryNameElement); | ||
}); | ||
|
||
// Bind action to save collection attribute and prevent default submit | ||
saveButtonElement.addEventListener('click', (e) => { | ||
e.preventDefault(); | ||
const data = {}; | ||
data.collection = document.getElementById(`id_${ soundId.toString() }-collection`).value; | ||
data.new_collection_name = document.getElementById(`id_${ soundId.toString() }-new_collection_name`).value; | ||
saveCollectionSound(collectionSoundUrl, data); | ||
}); | ||
}; | ||
|
||
const bindCollectionModals = (container) => { | ||
const collectionButtons = [...container.querySelectorAll('[data-toggle="collection-modal"]')]; | ||
collectionButtons.forEach(element => { | ||
if (element.dataset.alreadyBinded !== undefined){ | ||
return; | ||
} | ||
element.dataset.alreadyBinded = true; | ||
element.addEventListener('click', (evt) => { | ||
evt.preventDefault(); | ||
const modalUrlSplitted = element.dataset.modalUrl.split('/'); | ||
const soundId = parseInt(modalUrlSplitted[modalUrlSplitted.length - 2], 10); | ||
if (!evt.altKey) { | ||
handleGenericModal(element.dataset.modalUrl, () => { | ||
initCollectionFormModal(soundId, element.dataset.collectionSoundUrl); | ||
}, undefined, true, true); | ||
} else { | ||
saveCollectionSound(element.dataset.collectionSoundUrl); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
export { bindCollectionModals }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class FscollectionsConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'fscollections' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename this to
ENABLE COLLECTIONS
?