Merge 39d28ee136
into edce66c44d
This commit is contained in:
commit
3b04e19196
2 changed files with 31 additions and 17 deletions
|
@ -86,10 +86,14 @@ class Map < ApplicationRecord
|
||||||
user&.stars&.where(map: self)&.exists? || false # return false, not nil
|
user&.stars&.where(map: self)&.exists? || false # return false, not nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fork_children_ids
|
||||||
|
Map.where(source_id: id).map(&:id)
|
||||||
|
end
|
||||||
|
|
||||||
def as_json(_options = {})
|
def as_json(_options = {})
|
||||||
json = super(
|
json = super(
|
||||||
methods: [:user_name, :user_image, :star_count, :topic_count, :synapse_count,
|
methods: [:user_name, :user_image, :star_count, :topic_count, :synapse_count,
|
||||||
:contributor_count, :collaborator_ids, :screenshot_url],
|
:contributor_count, :collaborator_ids, :screenshot_url, :fork_children_ids],
|
||||||
except: [:screenshot_content_type, :screenshot_file_size, :screenshot_file_name,
|
except: [:screenshot_content_type, :screenshot_file_size, :screenshot_file_name,
|
||||||
:screenshot_updated_at]
|
:screenshot_updated_at]
|
||||||
)
|
)
|
||||||
|
|
|
@ -362,26 +362,36 @@ const InfoBox = {
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
},
|
},
|
||||||
deleteActiveMap: function() {
|
deleteActiveMap: function() {
|
||||||
var confirmString = 'Are you sure you want to delete this map? '
|
let confirmString = 'Are you sure you want to delete this map? '
|
||||||
confirmString += 'This action is irreversible. It will not delete the topics and synapses on the map.'
|
confirmString += 'This action is irreversible. It will not delete the topics and synapses on the map.'
|
||||||
|
|
||||||
var doIt = window.confirm(confirmString)
|
const doIt = window.confirm(confirmString)
|
||||||
var map = Active.Map
|
const map = Active.Map
|
||||||
var mapper = Active.Mapper
|
const authorized = map.authorizePermissionChange(Active.Mapper)
|
||||||
var authorized = map.authorizePermissionChange(mapper)
|
|
||||||
|
|
||||||
if (doIt && authorized) {
|
if (!doIt) {
|
||||||
InfoBox.close()
|
return
|
||||||
DataModel.Maps.Active.remove(map)
|
|
||||||
DataModel.Maps.Featured.remove(map)
|
|
||||||
DataModel.Maps.Mine.remove(map)
|
|
||||||
DataModel.Maps.Shared.remove(map)
|
|
||||||
map.destroy()
|
|
||||||
browserHistory.push('/')
|
|
||||||
GlobalUI.notifyUser('Map eliminated')
|
|
||||||
} else if (!authorized) {
|
|
||||||
window.alert("Hey now. We can't just go around willy nilly deleting other people's maps now can we? Run off and find something constructive to do, eh?")
|
|
||||||
}
|
}
|
||||||
|
if (!authorized) {
|
||||||
|
window.alert("Hey now. We can't just go around willy nilly deleting other people's maps now can we? Run off and find something constructive to do, eh?")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (map.fork_children_ids.length > 0) {
|
||||||
|
let forkMessage = "This map has been forked, so it can't be deleted. The forked map idss are:"
|
||||||
|
forkMessage += map.fork_children_ids.join(', ')
|
||||||
|
window.alert(forkMessage)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// confirmed deletion, authorized, and no fork children
|
||||||
|
InfoBox.close()
|
||||||
|
DataModel.Maps.Active.remove(map)
|
||||||
|
DataModel.Maps.Featured.remove(map)
|
||||||
|
DataModel.Maps.Mine.remove(map)
|
||||||
|
DataModel.Maps.Shared.remove(map)
|
||||||
|
map.destroy()
|
||||||
|
browserHistory.push('/')
|
||||||
|
GlobalUI.notifyUser('Map eliminated')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue