Merge branch 'develop'
This commit is contained in:
commit
b0860ef670
85 changed files with 8449 additions and 7803 deletions
|
@ -7,7 +7,9 @@ export DB_NAME='metamap002'
|
||||||
export REALTIME_SERVER='http://localhost:5001'
|
export REALTIME_SERVER='http://localhost:5001'
|
||||||
export MAILER_DEFAULT_URL='localhost:3000'
|
export MAILER_DEFAULT_URL='localhost:3000'
|
||||||
export DEVISE_MAILER_SENDER='team@metamaps.cc'
|
export DEVISE_MAILER_SENDER='team@metamaps.cc'
|
||||||
|
|
||||||
export DEVISE_SECRET_KEY='f71c467e526f23d614b3b08866cad4788c502bed869c282f06e73ee6c94675b62fe1f6d52fa7ba8196b33031f0d2f3b67e27ea07693c52ecebccb01700cad614'
|
export DEVISE_SECRET_KEY='f71c467e526f23d614b3b08866cad4788c502bed869c282f06e73ee6c94675b62fe1f6d52fa7ba8196b33031f0d2f3b67e27ea07693c52ecebccb01700cad614'
|
||||||
|
export SECRET_KEY_BASE='267c8a84f63963282f45bc3010eaddf027abfab58fc759d6e239c8005f85ee99d6d01b1ab6394cdee9ca7f8c9213a0cf91d3d8d3350f096123e2caccbcc0924f'
|
||||||
|
|
||||||
# # you can safely leave these blank, unless you're deploying an instance, in
|
# # you can safely leave these blank, unless you're deploying an instance, in
|
||||||
# # which case you'll need to set them up
|
# # which case you'll need to set them up
|
||||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -5,10 +5,10 @@
|
||||||
# git config --global core.excludesfile ~/.gitignore_global
|
# git config --global core.excludesfile ~/.gitignore_global
|
||||||
|
|
||||||
#assety stuff
|
#assety stuff
|
||||||
realtime/node_modules
|
|
||||||
public/assets
|
public/assets
|
||||||
public/metamaps_mobile
|
public/metamaps_mobile
|
||||||
vendor/
|
vendor/
|
||||||
|
node_modules
|
||||||
|
|
||||||
#secrets and config
|
#secrets and config
|
||||||
.env
|
.env
|
||||||
|
|
12
.travis.yml
12
.travis.yml
|
@ -1,9 +1,21 @@
|
||||||
sudo: false
|
sudo: false
|
||||||
language: ruby
|
language: ruby
|
||||||
|
cache:
|
||||||
|
bundler: true
|
||||||
|
directories:
|
||||||
|
- app/assets/javascripts/node_modules
|
||||||
rvm:
|
rvm:
|
||||||
- 2.1.3
|
- 2.1.3
|
||||||
before_script:
|
before_script:
|
||||||
|
- echo "Rspec setup"
|
||||||
- export RAILS_ENV=test
|
- export RAILS_ENV=test
|
||||||
- cp .example-env .env
|
- cp .example-env .env
|
||||||
- bundle exec rake db:create
|
- bundle exec rake db:create
|
||||||
- bundle exec rake db:schema:load
|
- bundle exec rake db:schema:load
|
||||||
|
- echo "node setup"
|
||||||
|
- . $HOME/.nvm/nvm.sh
|
||||||
|
- nvm install stable
|
||||||
|
- nvm use stable
|
||||||
|
- (cd app/assets/javascripts && npm install)
|
||||||
|
script:
|
||||||
|
- bundle exec rspec && (cd app/assets/javascripts && npm test)
|
||||||
|
|
2
Gemfile
2
Gemfile
|
@ -10,7 +10,7 @@ gem 'delayed_job', '~> 4.0.2'
|
||||||
gem 'delayed_job_active_record', '~> 4.0.1'
|
gem 'delayed_job_active_record', '~> 4.0.1'
|
||||||
gem 'devise'
|
gem 'devise'
|
||||||
gem 'doorkeeper'
|
gem 'doorkeeper'
|
||||||
gem 'dotenv'
|
gem 'dotenv-rails'
|
||||||
gem 'exception_notification'
|
gem 'exception_notification'
|
||||||
gem 'formtastic'
|
gem 'formtastic'
|
||||||
gem 'formula'
|
gem 'formula'
|
||||||
|
|
|
@ -87,7 +87,10 @@ GEM
|
||||||
docile (1.1.5)
|
docile (1.1.5)
|
||||||
doorkeeper (3.1.0)
|
doorkeeper (3.1.0)
|
||||||
railties (>= 3.2)
|
railties (>= 3.2)
|
||||||
dotenv (2.1.0)
|
dotenv (2.1.1)
|
||||||
|
dotenv-rails (2.1.1)
|
||||||
|
dotenv (= 2.1.1)
|
||||||
|
railties (>= 4.0, < 5.1)
|
||||||
erubis (2.7.0)
|
erubis (2.7.0)
|
||||||
exception_notification (4.1.4)
|
exception_notification (4.1.4)
|
||||||
actionmailer (~> 4.0)
|
actionmailer (~> 4.0)
|
||||||
|
@ -273,7 +276,7 @@ DEPENDENCIES
|
||||||
delayed_job_active_record (~> 4.0.1)
|
delayed_job_active_record (~> 4.0.1)
|
||||||
devise
|
devise
|
||||||
doorkeeper
|
doorkeeper
|
||||||
dotenv
|
dotenv-rails
|
||||||
exception_notification
|
exception_notification
|
||||||
factory_girl_rails
|
factory_girl_rails
|
||||||
formtastic
|
formtastic
|
||||||
|
|
BIN
app/assets/images/addcollab_sprite.png
Normal file
BIN
app/assets/images/addcollab_sprite.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 322 B |
BIN
app/assets/images/exploremaps_sprite.png
Executable file → Normal file
BIN
app/assets/images/exploremaps_sprite.png
Executable file → Normal file
Binary file not shown.
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 2.2 KiB |
BIN
app/assets/images/mm_logo.png
Normal file
BIN
app/assets/images/mm_logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3 KiB |
BIN
app/assets/images/removecollab_sprite.png
Normal file
BIN
app/assets/images/removecollab_sprite.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 418 B |
9
app/assets/javascripts/README-testing-js.md
Normal file
9
app/assets/javascripts/README-testing-js.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
Change directories to where this file is, and then run
|
||||||
|
|
||||||
|
npm install
|
||||||
|
|
||||||
|
to set up your testing environment. Then use
|
||||||
|
|
||||||
|
npm test
|
||||||
|
|
||||||
|
to see the results of testing the current javascript files.
|
|
@ -24,7 +24,23 @@
|
||||||
//= require ./src/views/videoView
|
//= require ./src/views/videoView
|
||||||
//= require ./src/views/room
|
//= require ./src/views/room
|
||||||
//= require ./src/JIT
|
//= require ./src/JIT
|
||||||
|
//= require ./src/check-canvas-support
|
||||||
//= require ./src/Metamaps
|
//= require ./src/Metamaps
|
||||||
|
//= require ./src/Metamaps.Create
|
||||||
|
//= require ./src/Metamaps.TopicCard
|
||||||
|
//= require ./src/Metamaps.SynapseCard
|
||||||
|
//= require ./src/Metamaps.Visualize
|
||||||
|
//= require ./src/Metamaps.Util
|
||||||
|
//= require ./src/Metamaps.Realtime
|
||||||
|
//= require ./src/Metamaps.Control
|
||||||
|
//= require ./src/Metamaps.Filter
|
||||||
|
//= require ./src/Metamaps.Listeners
|
||||||
|
//= require ./src/Metamaps.Organize
|
||||||
|
//= require ./src/Metamaps.Topic
|
||||||
|
//= require ./src/Metamaps.Synapse
|
||||||
|
//= require ./src/Metamaps.Map
|
||||||
|
//= require ./src/Metamaps.Account
|
||||||
|
//= require ./src/Metamaps.Mapper
|
||||||
//= require ./src/Metamaps.Admin
|
//= require ./src/Metamaps.Admin
|
||||||
//= require ./src/Metamaps.Import
|
//= require ./src/Metamaps.Import
|
||||||
//= require ./src/Metamaps.JIT
|
//= require ./src/Metamaps.JIT
|
||||||
|
|
22
app/assets/javascripts/package.json
Normal file
22
app/assets/javascripts/package.json
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
"name": "metamaps-frontend",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Metamaps frontend - currently just tests",
|
||||||
|
"scripts": {
|
||||||
|
"test": "mocha test || echo 'Run `npm install` to setup testing'"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/metamaps/metamaps.git"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "AGPL-3.0",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/metamaps/metamaps/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/metamaps/metamaps#readme",
|
||||||
|
"devDependencies": {
|
||||||
|
"chai": "^3.5.0",
|
||||||
|
"mocha": "^2.4.5"
|
||||||
|
}
|
||||||
|
}
|
122
app/assets/javascripts/src/Metamaps.Account.js
Normal file
122
app/assets/javascripts/src/Metamaps.Account.js
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
/* global Metamaps, $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Metamaps.Account.js.erb
|
||||||
|
*
|
||||||
|
* Dependencies:
|
||||||
|
* - Metamaps.Erb
|
||||||
|
*/
|
||||||
|
|
||||||
|
Metamaps.Account = {
|
||||||
|
listenersInitialized: false,
|
||||||
|
init: function () {
|
||||||
|
var self = Metamaps.Account
|
||||||
|
},
|
||||||
|
initListeners: function () {
|
||||||
|
var self = Metamaps.Account
|
||||||
|
|
||||||
|
$('#user_image').change(self.showImagePreview)
|
||||||
|
self.listenersInitialized = true
|
||||||
|
},
|
||||||
|
toggleChangePicture: function () {
|
||||||
|
var self = Metamaps.Account
|
||||||
|
|
||||||
|
$('.userImageMenu').toggle()
|
||||||
|
if (!self.listenersInitialized) self.initListeners()
|
||||||
|
},
|
||||||
|
openChangePicture: function () {
|
||||||
|
var self = Metamaps.Account
|
||||||
|
|
||||||
|
$('.userImageMenu').show()
|
||||||
|
if (!self.listenersInitialized) self.initListeners()
|
||||||
|
},
|
||||||
|
closeChangePicture: function () {
|
||||||
|
var self = Metamaps.Account
|
||||||
|
|
||||||
|
$('.userImageMenu').hide()
|
||||||
|
},
|
||||||
|
showLoading: function () {
|
||||||
|
var self = Metamaps.Account
|
||||||
|
|
||||||
|
var loader = new CanvasLoader('accountPageLoading')
|
||||||
|
loader.setColor('#4FC059'); // default is '#000000'
|
||||||
|
loader.setDiameter(28) // default is 40
|
||||||
|
loader.setDensity(41) // default is 40
|
||||||
|
loader.setRange(0.9); // default is 1.3
|
||||||
|
loader.show() // Hidden by default
|
||||||
|
$('#accountPageLoading').show()
|
||||||
|
},
|
||||||
|
showImagePreview: function () {
|
||||||
|
var self = Metamaps.Account
|
||||||
|
|
||||||
|
var file = $('#user_image')[0].files[0]
|
||||||
|
|
||||||
|
var reader = new FileReader()
|
||||||
|
|
||||||
|
reader.onload = function (e) {
|
||||||
|
var $canvas = $('<canvas>').attr({
|
||||||
|
width: 84,
|
||||||
|
height: 84
|
||||||
|
})
|
||||||
|
var context = $canvas[0].getContext('2d')
|
||||||
|
var imageObj = new Image()
|
||||||
|
|
||||||
|
imageObj.onload = function () {
|
||||||
|
$('.userImageDiv canvas').remove()
|
||||||
|
$('.userImageDiv img').hide()
|
||||||
|
|
||||||
|
var imgWidth = imageObj.width
|
||||||
|
var imgHeight = imageObj.height
|
||||||
|
|
||||||
|
var dimensionToMatch = imgWidth > imgHeight ? imgHeight : imgWidth
|
||||||
|
// draw cropped image
|
||||||
|
var nonZero = Math.abs(imgHeight - imgWidth) / 2
|
||||||
|
var sourceX = dimensionToMatch === imgWidth ? 0 : nonZero
|
||||||
|
var sourceY = dimensionToMatch === imgHeight ? 0 : nonZero
|
||||||
|
var sourceWidth = dimensionToMatch
|
||||||
|
var sourceHeight = dimensionToMatch
|
||||||
|
var destX = 0
|
||||||
|
var destY = 0
|
||||||
|
var destWidth = 84
|
||||||
|
var destHeight = 84
|
||||||
|
|
||||||
|
context.drawImage(imageObj, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight)
|
||||||
|
$('.userImageDiv').prepend($canvas)
|
||||||
|
}
|
||||||
|
imageObj.src = reader.result
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file) {
|
||||||
|
reader.readAsDataURL(file)
|
||||||
|
$('.userImageMenu').hide()
|
||||||
|
$('#remove_image').val('0')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
removePicture: function () {
|
||||||
|
var self = Metamaps.Account
|
||||||
|
|
||||||
|
$('.userImageDiv canvas').remove()
|
||||||
|
$('.userImageDiv img').attr('src', Metamaps.Erb['user.png']).show()
|
||||||
|
$('.userImageMenu').hide()
|
||||||
|
|
||||||
|
var input = $('#user_image')
|
||||||
|
input.replaceWith(input.val('').clone(true))
|
||||||
|
$('#remove_image').val('1')
|
||||||
|
},
|
||||||
|
changeName: function () {
|
||||||
|
$('.accountName').hide()
|
||||||
|
$('.changeName').show()
|
||||||
|
},
|
||||||
|
showPass: function () {
|
||||||
|
$('.toHide').show()
|
||||||
|
$('.changePass').hide()
|
||||||
|
},
|
||||||
|
hidePass: function () {
|
||||||
|
$('.toHide').hide()
|
||||||
|
$('.changePass').show()
|
||||||
|
|
||||||
|
$('#current_password').val('')
|
||||||
|
$('#user_password').val('')
|
||||||
|
$('#user_password_confirmation').val('')
|
||||||
|
}
|
||||||
|
}
|
723
app/assets/javascripts/src/Metamaps.Backbone.js
Normal file
723
app/assets/javascripts/src/Metamaps.Backbone.js
Normal file
|
@ -0,0 +1,723 @@
|
||||||
|
/* global Metamaps, Backbone, _, $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Metamaps.Backbone.js.erb
|
||||||
|
*
|
||||||
|
* Dependencies:
|
||||||
|
* - Metamaps.Active
|
||||||
|
* - Metamaps.Collaborators
|
||||||
|
* - Metamaps.Creators
|
||||||
|
* - Metamaps.Filter
|
||||||
|
* - Metamaps.JIT
|
||||||
|
* - Metamaps.Loading
|
||||||
|
* - Metamaps.Map
|
||||||
|
* - Metamaps.Mapper
|
||||||
|
* - Metamaps.Mappers
|
||||||
|
* - Metamaps.Mappings
|
||||||
|
* - Metamaps.Metacodes
|
||||||
|
* - Metamaps.Realtime
|
||||||
|
* - Metamaps.Synapse
|
||||||
|
* - Metamaps.SynapseCard
|
||||||
|
* - Metamaps.Synapses
|
||||||
|
* - Metamaps.Topic
|
||||||
|
* - Metamaps.TopicCard
|
||||||
|
* - Metamaps.Topics
|
||||||
|
* - Metamaps.Visualize
|
||||||
|
*/
|
||||||
|
|
||||||
|
Metamaps.Backbone = {}
|
||||||
|
|
||||||
|
Metamaps.Backbone.Map = Backbone.Model.extend({
|
||||||
|
urlRoot: '/maps',
|
||||||
|
blacklist: ['created_at', 'updated_at', 'created_at_clean', 'updated_at_clean', 'user_name', 'contributor_count', 'topic_count', 'synapse_count', 'topics', 'synapses', 'mappings', 'mappers'],
|
||||||
|
toJSON: function (options) {
|
||||||
|
return _.omit(this.attributes, this.blacklist)
|
||||||
|
},
|
||||||
|
save: function (key, val, options) {
|
||||||
|
var attrs
|
||||||
|
|
||||||
|
// Handle both `"key", value` and `{key: value}` -style arguments.
|
||||||
|
if (key == null || typeof key === 'object') {
|
||||||
|
attrs = key
|
||||||
|
options = val
|
||||||
|
} else {
|
||||||
|
(attrs = {})[key] = val
|
||||||
|
}
|
||||||
|
|
||||||
|
var newOptions = options || {}
|
||||||
|
var s = newOptions.success
|
||||||
|
|
||||||
|
newOptions.success = function (model, response, opt) {
|
||||||
|
if (s) s(model, response, opt)
|
||||||
|
model.trigger('saved')
|
||||||
|
}
|
||||||
|
return Backbone.Model.prototype.save.call(this, attrs, newOptions)
|
||||||
|
},
|
||||||
|
initialize: function () {
|
||||||
|
this.on('changeByOther', this.updateView)
|
||||||
|
this.on('saved', this.savedEvent)
|
||||||
|
},
|
||||||
|
savedEvent: function () {
|
||||||
|
Metamaps.Realtime.sendMapChange(this)
|
||||||
|
},
|
||||||
|
authorizeToEdit: function (mapper) {
|
||||||
|
if (mapper && (
|
||||||
|
this.get('permission') === 'commons' ||
|
||||||
|
this.get('collaborator_ids').includes(mapper.get('id')) ||
|
||||||
|
this.get('user_id') === mapper.get('id'))) {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
authorizePermissionChange: function (mapper) {
|
||||||
|
if (mapper && this.get('user_id') === mapper.get('id')) {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getUser: function () {
|
||||||
|
return Metamaps.Mapper.get(this.get('user_id'))
|
||||||
|
},
|
||||||
|
fetchContained: function () {
|
||||||
|
var bb = Metamaps.Backbone
|
||||||
|
var that = this
|
||||||
|
var start = function (data) {
|
||||||
|
that.set('mappers', new bb.MapperCollection(data.mappers))
|
||||||
|
that.set('topics', new bb.TopicCollection(data.topics))
|
||||||
|
that.set('synapses', new bb.SynapseCollection(data.synapses))
|
||||||
|
that.set('mappings', new bb.MappingCollection(data.mappings))
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/maps/' + this.id + '/contains.json',
|
||||||
|
success: start,
|
||||||
|
error: errorFunc,
|
||||||
|
async: false
|
||||||
|
})
|
||||||
|
},
|
||||||
|
getTopics: function () {
|
||||||
|
if (!this.get('topics')) {
|
||||||
|
this.fetchContained()
|
||||||
|
}
|
||||||
|
return this.get('topics')
|
||||||
|
},
|
||||||
|
getSynapses: function () {
|
||||||
|
if (!this.get('synapses')) {
|
||||||
|
this.fetchContained()
|
||||||
|
}
|
||||||
|
return this.get('synapses')
|
||||||
|
},
|
||||||
|
getMappings: function () {
|
||||||
|
if (!this.get('mappings')) {
|
||||||
|
this.fetchContained()
|
||||||
|
}
|
||||||
|
return this.get('mappings')
|
||||||
|
},
|
||||||
|
getMappers: function () {
|
||||||
|
if (!this.get('mappers')) {
|
||||||
|
this.fetchContained()
|
||||||
|
}
|
||||||
|
return this.get('mappers')
|
||||||
|
},
|
||||||
|
attrForCards: function () {
|
||||||
|
function capitalize (string) {
|
||||||
|
return string.charAt(0).toUpperCase() + string.slice(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
var n = this.get('name')
|
||||||
|
var d = this.get('desc')
|
||||||
|
|
||||||
|
var maxNameLength = 32
|
||||||
|
var maxDescLength = 118
|
||||||
|
var truncatedName = n ? (n.length > maxNameLength ? n.substring(0, maxNameLength) + '...' : n) : ''
|
||||||
|
var truncatedDesc = d ? (d.length > maxDescLength ? d.substring(0, maxDescLength) + '...' : d) : ''
|
||||||
|
|
||||||
|
var obj = {
|
||||||
|
id: this.id,
|
||||||
|
name: truncatedName,
|
||||||
|
fullName: n,
|
||||||
|
desc: truncatedDesc,
|
||||||
|
permission: this.get('permission') ? capitalize(this.get('permission')) : 'Commons',
|
||||||
|
editPermission: this.authorizeToEdit(Metamaps.Active.Mapper) ? 'canEdit' : 'cannotEdit',
|
||||||
|
contributor_count_number: '<span class="cCountColor">' + this.get('contributor_count') + '</span>',
|
||||||
|
contributor_count_string: this.get('contributor_count') === 1 ? ' contributor' : ' contributors',
|
||||||
|
topic_count_number: '<span class="tCountColor">' + this.get('topic_count') + '</span>',
|
||||||
|
topic_count_string: this.get('topic_count') === 1 ? ' topic' : ' topics',
|
||||||
|
synapse_count_number: '<span class="sCountColor">' + this.get('synapse_count') + '</span>',
|
||||||
|
synapse_count_string: this.get('synapse_count') === 1 ? ' synapse' : ' synapses',
|
||||||
|
screenshot: '<img src="' + this.get('screenshot_url') + '" />'
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
},
|
||||||
|
updateView: function () {
|
||||||
|
var map = Metamaps.Active.Map
|
||||||
|
var isActiveMap = this.id === map.id
|
||||||
|
if (isActiveMap) {
|
||||||
|
Metamaps.Map.InfoBox.updateNameDescPerm(this.get('name'), this.get('desc'), this.get('permission'))
|
||||||
|
this.updateMapWrapper()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateMapWrapper: function () {
|
||||||
|
var map = Metamaps.Active.Map
|
||||||
|
var isActiveMap = this.id === map.id
|
||||||
|
var authorized = map && map.authorizeToEdit(Metamaps.Active.Mapper) ? 'canEditMap' : ''
|
||||||
|
var commonsMap = map && map.get('permission') === 'commons' ? 'commonsMap' : ''
|
||||||
|
if (isActiveMap) {
|
||||||
|
$('.wrapper').removeClass('canEditMap commonsMap').addClass(authorized + ' ' + commonsMap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Metamaps.Backbone.MapsCollection = Backbone.Collection.extend({
|
||||||
|
model: Metamaps.Backbone.Map,
|
||||||
|
initialize: function (models, options) {
|
||||||
|
this.id = options.id
|
||||||
|
this.sortBy = options.sortBy
|
||||||
|
|
||||||
|
if (options.mapperId) {
|
||||||
|
this.mapperId = options.mapperId
|
||||||
|
}
|
||||||
|
|
||||||
|
// this.page represents the NEXT page to fetch
|
||||||
|
this.page = models.length > 0 ? (models.length < 20 ? 'loadedAll' : 2) : 1
|
||||||
|
},
|
||||||
|
url: function () {
|
||||||
|
if (!this.mapperId) {
|
||||||
|
return '/explore/' + this.id + '.json'
|
||||||
|
} else {
|
||||||
|
return '/explore/mapper/' + this.mapperId + '.json'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
comparator: function (a, b) {
|
||||||
|
a = a.get(this.sortBy)
|
||||||
|
b = b.get(this.sortBy)
|
||||||
|
var temp
|
||||||
|
if (this.sortBy === 'name') {
|
||||||
|
a = a ? a.toLowerCase() : ''
|
||||||
|
b = b ? b.toLowerCase() : ''
|
||||||
|
} else {
|
||||||
|
// this is for updated_at and created_at
|
||||||
|
temp = a
|
||||||
|
a = b
|
||||||
|
b = temp
|
||||||
|
a = (new Date(a)).getTime()
|
||||||
|
b = (new Date(b)).getTime()
|
||||||
|
}
|
||||||
|
return a > b ? 1 : a < b ? -1 : 0
|
||||||
|
},
|
||||||
|
getMaps: function (cb) {
|
||||||
|
var self = this
|
||||||
|
|
||||||
|
Metamaps.Loading.show()
|
||||||
|
|
||||||
|
if (this.page !== 'loadedAll') {
|
||||||
|
var numBefore = this.length
|
||||||
|
this.fetch({
|
||||||
|
remove: false,
|
||||||
|
silent: true,
|
||||||
|
data: { page: this.page },
|
||||||
|
success: function (collection, response, options) {
|
||||||
|
// you can pass additional options to the event you trigger here as well
|
||||||
|
if (collection.length - numBefore < 20) {
|
||||||
|
self.page = 'loadedAll'
|
||||||
|
} else {
|
||||||
|
self.page += 1
|
||||||
|
}
|
||||||
|
self.trigger('successOnFetch', cb)
|
||||||
|
},
|
||||||
|
error: function (collection, response, options) {
|
||||||
|
// you can pass additional options to the event you trigger here as well
|
||||||
|
self.trigger('errorOnFetch')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
self.trigger('successOnFetch', cb)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
Metamaps.Backbone.Message = Backbone.Model.extend({
|
||||||
|
urlRoot: '/messages',
|
||||||
|
blacklist: ['created_at', 'updated_at'],
|
||||||
|
toJSON: function (options) {
|
||||||
|
return _.omit(this.attributes, this.blacklist)
|
||||||
|
},
|
||||||
|
prepareLiForFilter: function () {
|
||||||
|
/* var li = ''
|
||||||
|
* li += '<li data-id="' + this.id.toString() + '">'
|
||||||
|
* li += '<img src="' + this.get("image") + '" data-id="' + this.id.toString() + '"'
|
||||||
|
* li += ' alt="' + this.get('name') + '" />'
|
||||||
|
* li += '<p>' + this.get('name') + '</p></li>'
|
||||||
|
* return li
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Metamaps.Backbone.MessageCollection = Backbone.Collection.extend({
|
||||||
|
model: Metamaps.Backbone.Message,
|
||||||
|
url: '/messages'
|
||||||
|
})
|
||||||
|
|
||||||
|
Metamaps.Backbone.Mapper = Backbone.Model.extend({
|
||||||
|
urlRoot: '/users',
|
||||||
|
blacklist: ['created_at', 'updated_at'],
|
||||||
|
toJSON: function (options) {
|
||||||
|
return _.omit(this.attributes, this.blacklist)
|
||||||
|
},
|
||||||
|
prepareLiForFilter: function () {
|
||||||
|
var li = ''
|
||||||
|
li += '<li data-id="' + this.id.toString() + '">'
|
||||||
|
li += '<img src="' + this.get('image') + '" data-id="' + this.id.toString() + '"'
|
||||||
|
li += ' alt="' + this.get('name') + '" />'
|
||||||
|
li += '<p>' + this.get('name') + '</p></li>'
|
||||||
|
return li
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
Metamaps.Backbone.MapperCollection = Backbone.Collection.extend({
|
||||||
|
model: Metamaps.Backbone.Mapper,
|
||||||
|
url: '/users'
|
||||||
|
})
|
||||||
|
|
||||||
|
Metamaps.Backbone.init = function () {
|
||||||
|
var self = Metamaps.Backbone
|
||||||
|
|
||||||
|
self.Metacode = Backbone.Model.extend({
|
||||||
|
initialize: function () {
|
||||||
|
var image = new Image()
|
||||||
|
image.crossOrigin = 'Anonymous'
|
||||||
|
image.src = this.get('icon')
|
||||||
|
this.set('image', image)
|
||||||
|
},
|
||||||
|
prepareLiForFilter: function () {
|
||||||
|
var li = ''
|
||||||
|
li += '<li data-id="' + this.id.toString() + '">'
|
||||||
|
li += '<img src="' + this.get('icon') + '" data-id="' + this.id.toString() + '"'
|
||||||
|
li += ' alt="' + this.get('name') + '" />'
|
||||||
|
li += '<p>' + this.get('name').toLowerCase() + '</p></li>'
|
||||||
|
return li
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
self.MetacodeCollection = Backbone.Collection.extend({
|
||||||
|
model: this.Metacode,
|
||||||
|
url: '/metacodes',
|
||||||
|
comparator: function (a, b) {
|
||||||
|
a = a.get('name').toLowerCase()
|
||||||
|
b = b.get('name').toLowerCase()
|
||||||
|
return a > b ? 1 : a < b ? -1 : 0
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
self.Topic = Backbone.Model.extend({
|
||||||
|
urlRoot: '/topics',
|
||||||
|
blacklist: ['node', 'created_at', 'updated_at', 'user_name', 'user_image', 'map_count', 'synapse_count'],
|
||||||
|
toJSON: function (options) {
|
||||||
|
return _.omit(this.attributes, this.blacklist)
|
||||||
|
},
|
||||||
|
save: function (key, val, options) {
|
||||||
|
var attrs
|
||||||
|
|
||||||
|
// Handle both `"key", value` and `{key: value}` -style arguments.
|
||||||
|
if (key == null || typeof key === 'object') {
|
||||||
|
attrs = key
|
||||||
|
options = val
|
||||||
|
} else {
|
||||||
|
(attrs = {})[key] = val
|
||||||
|
}
|
||||||
|
|
||||||
|
var newOptions = options || {}
|
||||||
|
var s = newOptions.success
|
||||||
|
|
||||||
|
var permBefore = this.get('permission')
|
||||||
|
|
||||||
|
newOptions.success = function (model, response, opt) {
|
||||||
|
if (s) s(model, response, opt)
|
||||||
|
model.trigger('saved')
|
||||||
|
|
||||||
|
if (permBefore === 'private' && model.get('permission') !== 'private') {
|
||||||
|
model.trigger('noLongerPrivate')
|
||||||
|
}
|
||||||
|
else if (permBefore !== 'private' && model.get('permission') === 'private') {
|
||||||
|
model.trigger('nowPrivate')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Backbone.Model.prototype.save.call(this, attrs, newOptions)
|
||||||
|
},
|
||||||
|
initialize: function () {
|
||||||
|
if (this.isNew()) {
|
||||||
|
this.set({
|
||||||
|
'user_id': Metamaps.Active.Mapper.id,
|
||||||
|
'desc': '',
|
||||||
|
'link': '',
|
||||||
|
'permission': Metamaps.Active.Map ? Metamaps.Active.Map.get('permission') : 'commons'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
this.on('changeByOther', this.updateCardView)
|
||||||
|
this.on('change', this.updateNodeView)
|
||||||
|
this.on('saved', this.savedEvent)
|
||||||
|
this.on('nowPrivate', function () {
|
||||||
|
var removeTopicData = {
|
||||||
|
mappableid: this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).trigger(Metamaps.JIT.events.removeTopic, [removeTopicData])
|
||||||
|
})
|
||||||
|
this.on('noLongerPrivate', function () {
|
||||||
|
var newTopicData = {
|
||||||
|
mappingid: this.getMapping().id,
|
||||||
|
mappableid: this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).trigger(Metamaps.JIT.events.newTopic, [newTopicData])
|
||||||
|
})
|
||||||
|
|
||||||
|
this.on('change:metacode_id', Metamaps.Filter.checkMetacodes, this)
|
||||||
|
},
|
||||||
|
authorizeToEdit: function (mapper) {
|
||||||
|
if (mapper &&
|
||||||
|
(this.get('calculated_permission') === 'commons' ||
|
||||||
|
this.get('collaborator_ids').includes(mapper.get('id')) ||
|
||||||
|
this.get('user_id') === mapper.get('id'))) {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
authorizePermissionChange: function (mapper) {
|
||||||
|
if (mapper && this.get('user_id') === mapper.get('id')) return true
|
||||||
|
else return false
|
||||||
|
},
|
||||||
|
getDate: function () {},
|
||||||
|
getMetacode: function () {
|
||||||
|
return Metamaps.Metacodes.get(this.get('metacode_id'))
|
||||||
|
},
|
||||||
|
getMapping: function () {
|
||||||
|
if (!Metamaps.Active.Map) return false
|
||||||
|
|
||||||
|
return Metamaps.Mappings.findWhere({
|
||||||
|
map_id: Metamaps.Active.Map.id,
|
||||||
|
mappable_type: 'Topic',
|
||||||
|
mappable_id: this.isNew() ? this.cid : this.id
|
||||||
|
})
|
||||||
|
},
|
||||||
|
createNode: function () {
|
||||||
|
var mapping
|
||||||
|
var node = {
|
||||||
|
adjacencies: [],
|
||||||
|
id: this.isNew() ? this.cid : this.id,
|
||||||
|
name: this.get('name')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Metamaps.Active.Map) {
|
||||||
|
mapping = this.getMapping()
|
||||||
|
node.data = {
|
||||||
|
$mapping: null,
|
||||||
|
$mappingID: mapping.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return node
|
||||||
|
},
|
||||||
|
updateNode: function () {
|
||||||
|
var mapping
|
||||||
|
var node = this.get('node')
|
||||||
|
node.setData('topic', this)
|
||||||
|
|
||||||
|
if (Metamaps.Active.Map) {
|
||||||
|
mapping = this.getMapping()
|
||||||
|
node.setData('mapping', mapping)
|
||||||
|
}
|
||||||
|
|
||||||
|
return node
|
||||||
|
},
|
||||||
|
savedEvent: function () {
|
||||||
|
Metamaps.Realtime.sendTopicChange(this)
|
||||||
|
},
|
||||||
|
updateViews: function () {
|
||||||
|
var onPageWithTopicCard = Metamaps.Active.Map || Metamaps.Active.Topic
|
||||||
|
var node = this.get('node')
|
||||||
|
// update topic card, if this topic is the one open there
|
||||||
|
if (onPageWithTopicCard && this == Metamaps.TopicCard.openTopicCard) {
|
||||||
|
Metamaps.TopicCard.showCard(node)
|
||||||
|
}
|
||||||
|
|
||||||
|
// update the node on the map
|
||||||
|
if (onPageWithTopicCard && node) {
|
||||||
|
node.name = this.get('name')
|
||||||
|
Metamaps.Visualize.mGraph.plot()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateCardView: function () {
|
||||||
|
var onPageWithTopicCard = Metamaps.Active.Map || Metamaps.Active.Topic
|
||||||
|
var node = this.get('node')
|
||||||
|
// update topic card, if this topic is the one open there
|
||||||
|
if (onPageWithTopicCard && this == Metamaps.TopicCard.openTopicCard) {
|
||||||
|
Metamaps.TopicCard.showCard(node)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateNodeView: function () {
|
||||||
|
var onPageWithTopicCard = Metamaps.Active.Map || Metamaps.Active.Topic
|
||||||
|
var node = this.get('node')
|
||||||
|
|
||||||
|
// update the node on the map
|
||||||
|
if (onPageWithTopicCard && node) {
|
||||||
|
node.name = this.get('name')
|
||||||
|
Metamaps.Visualize.mGraph.plot()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
self.TopicCollection = Backbone.Collection.extend({
|
||||||
|
model: self.Topic,
|
||||||
|
url: '/topics'
|
||||||
|
})
|
||||||
|
|
||||||
|
self.Synapse = Backbone.Model.extend({
|
||||||
|
urlRoot: '/synapses',
|
||||||
|
blacklist: ['edge', 'created_at', 'updated_at'],
|
||||||
|
toJSON: function (options) {
|
||||||
|
return _.omit(this.attributes, this.blacklist)
|
||||||
|
},
|
||||||
|
save: function (key, val, options) {
|
||||||
|
var attrs
|
||||||
|
|
||||||
|
// Handle both `"key", value` and `{key: value}` -style arguments.
|
||||||
|
if (key == null || typeof key === 'object') {
|
||||||
|
attrs = key
|
||||||
|
options = val
|
||||||
|
} else {
|
||||||
|
(attrs = {})[key] = val
|
||||||
|
}
|
||||||
|
|
||||||
|
var newOptions = options || {}
|
||||||
|
var s = newOptions.success
|
||||||
|
|
||||||
|
var permBefore = this.get('permission')
|
||||||
|
|
||||||
|
newOptions.success = function (model, response, opt) {
|
||||||
|
if (s) s(model, response, opt)
|
||||||
|
model.trigger('saved')
|
||||||
|
|
||||||
|
if (permBefore === 'private' && model.get('permission') !== 'private') {
|
||||||
|
model.trigger('noLongerPrivate')
|
||||||
|
}
|
||||||
|
else if (permBefore !== 'private' && model.get('permission') === 'private') {
|
||||||
|
model.trigger('nowPrivate')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Backbone.Model.prototype.save.call(this, attrs, newOptions)
|
||||||
|
},
|
||||||
|
initialize: function () {
|
||||||
|
if (this.isNew()) {
|
||||||
|
this.set({
|
||||||
|
'user_id': Metamaps.Active.Mapper.id,
|
||||||
|
'permission': Metamaps.Active.Map ? Metamaps.Active.Map.get('permission') : 'commons',
|
||||||
|
'category': 'from-to'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
this.on('changeByOther', this.updateCardView)
|
||||||
|
this.on('change', this.updateEdgeView)
|
||||||
|
this.on('saved', this.savedEvent)
|
||||||
|
this.on('noLongerPrivate', function () {
|
||||||
|
var newSynapseData = {
|
||||||
|
mappingid: this.getMapping().id,
|
||||||
|
mappableid: this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).trigger(Metamaps.JIT.events.newSynapse, [newSynapseData])
|
||||||
|
})
|
||||||
|
this.on('nowPrivate', function () {
|
||||||
|
$(document).trigger(Metamaps.JIT.events.removeSynapse, [{
|
||||||
|
mappableid: this.id
|
||||||
|
}])
|
||||||
|
})
|
||||||
|
|
||||||
|
this.on('change:desc', Metamaps.Filter.checkSynapses, this)
|
||||||
|
},
|
||||||
|
prepareLiForFilter: function () {
|
||||||
|
var li = ''
|
||||||
|
li += '<li data-id="' + this.get('desc') + '">'
|
||||||
|
li += '<img src="' + Metamaps.Erb['synapse16.png'] + '"'
|
||||||
|
li += ' alt="synapse icon" />'
|
||||||
|
li += '<p>' + this.get('desc') + '</p></li>'
|
||||||
|
return li
|
||||||
|
},
|
||||||
|
authorizeToEdit: function (mapper) {
|
||||||
|
if (mapper && (this.get('calculated_permission') === 'commons' || this.get('collaborator_ids').includes(mapper.get('id')) || this.get('user_id') === mapper.get('id'))) return true
|
||||||
|
else return false
|
||||||
|
},
|
||||||
|
authorizePermissionChange: function (mapper) {
|
||||||
|
if (mapper && this.get('user_id') === mapper.get('id')) return true
|
||||||
|
else return false
|
||||||
|
},
|
||||||
|
getTopic1: function () {
|
||||||
|
return Metamaps.Topics.get(this.get('node1_id'))
|
||||||
|
},
|
||||||
|
getTopic2: function () {
|
||||||
|
return Metamaps.Topics.get(this.get('node2_id'))
|
||||||
|
},
|
||||||
|
getDirection: function () {
|
||||||
|
var t1 = this.getTopic1(),
|
||||||
|
t2 = this.getTopic2()
|
||||||
|
|
||||||
|
return t1 && t2 ? [
|
||||||
|
t1.get('node').id,
|
||||||
|
t2.get('node').id
|
||||||
|
] : false
|
||||||
|
},
|
||||||
|
getMapping: function () {
|
||||||
|
if (!Metamaps.Active.Map) return false
|
||||||
|
|
||||||
|
return Metamaps.Mappings.findWhere({
|
||||||
|
map_id: Metamaps.Active.Map.id,
|
||||||
|
mappable_type: 'Synapse',
|
||||||
|
mappable_id: this.isNew() ? this.cid : this.id
|
||||||
|
})
|
||||||
|
},
|
||||||
|
createEdge: function (providedMapping) {
|
||||||
|
var mapping, mappingID
|
||||||
|
var synapseID = this.isNew() ? this.cid : this.id
|
||||||
|
|
||||||
|
var edge = {
|
||||||
|
nodeFrom: this.get('node1_id'),
|
||||||
|
nodeTo: this.get('node2_id'),
|
||||||
|
data: {
|
||||||
|
$synapses: [],
|
||||||
|
$synapseIDs: [synapseID],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Metamaps.Active.Map) {
|
||||||
|
mapping = providedMapping || this.getMapping()
|
||||||
|
mappingID = mapping.isNew() ? mapping.cid : mapping.id
|
||||||
|
edge.data.$mappings = []
|
||||||
|
edge.data.$mappingIDs = [mappingID]
|
||||||
|
}
|
||||||
|
|
||||||
|
return edge
|
||||||
|
},
|
||||||
|
updateEdge: function () {
|
||||||
|
var mapping
|
||||||
|
var edge = this.get('edge')
|
||||||
|
edge.getData('synapses').push(this)
|
||||||
|
|
||||||
|
if (Metamaps.Active.Map) {
|
||||||
|
mapping = this.getMapping()
|
||||||
|
edge.getData('mappings').push(mapping)
|
||||||
|
}
|
||||||
|
|
||||||
|
return edge
|
||||||
|
},
|
||||||
|
savedEvent: function () {
|
||||||
|
Metamaps.Realtime.sendSynapseChange(this)
|
||||||
|
},
|
||||||
|
updateViews: function () {
|
||||||
|
this.updateCardView()
|
||||||
|
this.updateEdgeView()
|
||||||
|
},
|
||||||
|
updateCardView: function () {
|
||||||
|
var onPageWithSynapseCard = Metamaps.Active.Map || Metamaps.Active.Topic
|
||||||
|
var edge = this.get('edge')
|
||||||
|
|
||||||
|
// update synapse card, if this synapse is the one open there
|
||||||
|
if (onPageWithSynapseCard && edge == Metamaps.SynapseCard.openSynapseCard) {
|
||||||
|
Metamaps.SynapseCard.showCard(edge)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateEdgeView: function () {
|
||||||
|
var onPageWithSynapseCard = Metamaps.Active.Map || Metamaps.Active.Topic
|
||||||
|
var edge = this.get('edge')
|
||||||
|
|
||||||
|
// update the edge on the map
|
||||||
|
if (onPageWithSynapseCard && edge) {
|
||||||
|
Metamaps.Visualize.mGraph.plot()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
self.SynapseCollection = Backbone.Collection.extend({
|
||||||
|
model: self.Synapse,
|
||||||
|
url: '/synapses'
|
||||||
|
})
|
||||||
|
|
||||||
|
self.Mapping = Backbone.Model.extend({
|
||||||
|
urlRoot: '/mappings',
|
||||||
|
blacklist: ['created_at', 'updated_at'],
|
||||||
|
toJSON: function (options) {
|
||||||
|
return _.omit(this.attributes, this.blacklist)
|
||||||
|
},
|
||||||
|
initialize: function () {
|
||||||
|
if (this.isNew()) {
|
||||||
|
this.set({
|
||||||
|
'user_id': Metamaps.Active.Mapper.id,
|
||||||
|
'map_id': Metamaps.Active.Map ? Metamaps.Active.Map.id : null
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getMap: function () {
|
||||||
|
return Metamaps.Map.get(this.get('map_id'))
|
||||||
|
},
|
||||||
|
getTopic: function () {
|
||||||
|
if (this.get('mappable_type') === 'Topic') return Metamaps.Topic.get(this.get('mappable_id'))
|
||||||
|
else return false
|
||||||
|
},
|
||||||
|
getSynapse: function () {
|
||||||
|
if (this.get('mappable_type') === 'Synapse') return Metamaps.Synapse.get(this.get('mappable_id'))
|
||||||
|
else return false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
self.MappingCollection = Backbone.Collection.extend({
|
||||||
|
model: self.Mapping,
|
||||||
|
url: '/mappings'
|
||||||
|
})
|
||||||
|
|
||||||
|
Metamaps.Metacodes = Metamaps.Metacodes ? new self.MetacodeCollection(Metamaps.Metacodes) : new self.MetacodeCollection()
|
||||||
|
|
||||||
|
Metamaps.Topics = Metamaps.Topics ? new self.TopicCollection(Metamaps.Topics) : new self.TopicCollection()
|
||||||
|
|
||||||
|
Metamaps.Synapses = Metamaps.Synapses ? new self.SynapseCollection(Metamaps.Synapses) : new self.SynapseCollection()
|
||||||
|
|
||||||
|
Metamaps.Mappers = Metamaps.Mappers ? new self.MapperCollection(Metamaps.Mappers) : new self.MapperCollection()
|
||||||
|
|
||||||
|
Metamaps.Collaborators = Metamaps.Collaborators ? new self.MapperCollection(Metamaps.Collaborators) : new self.MapperCollection()
|
||||||
|
|
||||||
|
// this is for topic view
|
||||||
|
Metamaps.Creators = Metamaps.Creators ? new self.MapperCollection(Metamaps.Creators) : new self.MapperCollection()
|
||||||
|
|
||||||
|
if (Metamaps.Active.Map) {
|
||||||
|
Metamaps.Mappings = Metamaps.Mappings ? new self.MappingCollection(Metamaps.Mappings) : new self.MappingCollection()
|
||||||
|
|
||||||
|
Metamaps.Active.Map = new self.Map(Metamaps.Active.Map)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Metamaps.Active.Topic) Metamaps.Active.Topic = new self.Topic(Metamaps.Active.Topic)
|
||||||
|
|
||||||
|
// attach collection event listeners
|
||||||
|
self.attachCollectionEvents = function () {
|
||||||
|
Metamaps.Topics.on('add remove', function (topic) {
|
||||||
|
Metamaps.Map.InfoBox.updateNumbers()
|
||||||
|
Metamaps.Filter.checkMetacodes()
|
||||||
|
Metamaps.Filter.checkMappers()
|
||||||
|
})
|
||||||
|
|
||||||
|
Metamaps.Synapses.on('add remove', function (synapse) {
|
||||||
|
Metamaps.Map.InfoBox.updateNumbers()
|
||||||
|
Metamaps.Filter.checkSynapses()
|
||||||
|
Metamaps.Filter.checkMappers()
|
||||||
|
})
|
||||||
|
|
||||||
|
if (Metamaps.Active.Map) {
|
||||||
|
Metamaps.Mappings.on('add remove', function (mapping) {
|
||||||
|
Metamaps.Map.InfoBox.updateNumbers()
|
||||||
|
Metamaps.Filter.checkSynapses()
|
||||||
|
Metamaps.Filter.checkMetacodes()
|
||||||
|
Metamaps.Filter.checkMappers()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.attachCollectionEvents()
|
||||||
|
}; // end Metamaps.Backbone.init
|
|
@ -1,256 +0,0 @@
|
||||||
/* global Metamaps, Backbone, _, $ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Metamaps.Backbone.js.erb
|
|
||||||
*
|
|
||||||
* Dependencies:
|
|
||||||
* - Metamaps.Active
|
|
||||||
* - Metamaps.Loading
|
|
||||||
* - Metamaps.Map
|
|
||||||
* - Metamaps.Mapper
|
|
||||||
* - Metamaps.Realtime
|
|
||||||
*/
|
|
||||||
|
|
||||||
Metamaps.Backbone = {}
|
|
||||||
|
|
||||||
Metamaps.Backbone.Map = Backbone.Model.extend({
|
|
||||||
urlRoot: '/maps',
|
|
||||||
blacklist: ['created_at', 'updated_at', 'created_at_clean', 'updated_at_clean', 'user_name', 'contributor_count', 'topic_count', 'synapse_count', 'topics', 'synapses', 'mappings', 'mappers'],
|
|
||||||
toJSON: function (options) {
|
|
||||||
return _.omit(this.attributes, this.blacklist)
|
|
||||||
},
|
|
||||||
save: function (key, val, options) {
|
|
||||||
var attrs
|
|
||||||
|
|
||||||
// Handle both `"key", value` and `{key: value}` -style arguments.
|
|
||||||
if (key == null || typeof key === 'object') {
|
|
||||||
attrs = key
|
|
||||||
options = val
|
|
||||||
} else {
|
|
||||||
(attrs = {})[key] = val
|
|
||||||
}
|
|
||||||
|
|
||||||
var newOptions = options || {}
|
|
||||||
var s = newOptions.success
|
|
||||||
|
|
||||||
newOptions.success = function (model, response, opt) {
|
|
||||||
if (s) s(model, response, opt)
|
|
||||||
model.trigger('saved')
|
|
||||||
}
|
|
||||||
return Backbone.Model.prototype.save.call(this, attrs, newOptions)
|
|
||||||
},
|
|
||||||
initialize: function () {
|
|
||||||
this.on('changeByOther', this.updateView)
|
|
||||||
this.on('saved', this.savedEvent)
|
|
||||||
},
|
|
||||||
savedEvent: function () {
|
|
||||||
Metamaps.Realtime.sendMapChange(this)
|
|
||||||
},
|
|
||||||
authorizeToEdit: function (mapper) {
|
|
||||||
if (mapper && (this.get('permission') === 'commons' || this.get('user_id') === mapper.get('id'))) return true
|
|
||||||
else return false
|
|
||||||
},
|
|
||||||
authorizePermissionChange: function (mapper) {
|
|
||||||
if (mapper && this.get('user_id') === mapper.get('id')) return true
|
|
||||||
else return false
|
|
||||||
},
|
|
||||||
getUser: function () {
|
|
||||||
return Metamaps.Mapper.get(this.get('user_id'))
|
|
||||||
},
|
|
||||||
fetchContained: function () {
|
|
||||||
var bb = Metamaps.Backbone
|
|
||||||
var that = this
|
|
||||||
var start = function (data) {
|
|
||||||
that.set('mappers', new bb.MapperCollection(data.mappers))
|
|
||||||
that.set('topics', new bb.TopicCollection(data.topics))
|
|
||||||
that.set('synapses', new bb.SynapseCollection(data.synapses))
|
|
||||||
that.set('mappings', new bb.MappingCollection(data.mappings))
|
|
||||||
}
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: '/maps/' + this.id + '/contains.json',
|
|
||||||
success: start,
|
|
||||||
async: false
|
|
||||||
})
|
|
||||||
},
|
|
||||||
getTopics: function () {
|
|
||||||
if (!this.get('topics')) {
|
|
||||||
this.fetchContained()
|
|
||||||
}
|
|
||||||
return this.get('topics')
|
|
||||||
},
|
|
||||||
getSynapses: function () {
|
|
||||||
if (!this.get('synapses')) {
|
|
||||||
this.fetchContained()
|
|
||||||
}
|
|
||||||
return this.get('synapses')
|
|
||||||
},
|
|
||||||
getMappings: function () {
|
|
||||||
if (!this.get('mappings')) {
|
|
||||||
this.fetchContained()
|
|
||||||
}
|
|
||||||
return this.get('mappings')
|
|
||||||
},
|
|
||||||
getMappers: function () {
|
|
||||||
if (!this.get('mappers')) {
|
|
||||||
this.fetchContained()
|
|
||||||
}
|
|
||||||
return this.get('mappers')
|
|
||||||
},
|
|
||||||
attrForCards: function () {
|
|
||||||
function capitalize (string) {
|
|
||||||
return string.charAt(0).toUpperCase() + string.slice(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
var n = this.get('name')
|
|
||||||
var d = this.get('desc')
|
|
||||||
|
|
||||||
var maxNameLength = 32
|
|
||||||
var maxDescLength = 118
|
|
||||||
var truncatedName = n ? (n.length > maxNameLength ? n.substring(0, maxNameLength) + '...' : n) : ''
|
|
||||||
var truncatedDesc = d ? (d.length > maxDescLength ? d.substring(0, maxDescLength) + '...' : d) : ''
|
|
||||||
|
|
||||||
var obj = {
|
|
||||||
id: this.id,
|
|
||||||
name: truncatedName,
|
|
||||||
fullName: n,
|
|
||||||
desc: truncatedDesc,
|
|
||||||
permission: this.get('permission') ? capitalize(this.get('permission')) : 'Commons',
|
|
||||||
editPermission: this.authorizeToEdit(Metamaps.Active.Mapper) ? 'canEdit' : 'cannotEdit',
|
|
||||||
contributor_count_number: '<span class="cCountColor">' + this.get('contributor_count') + '</span>',
|
|
||||||
contributor_count_string: this.get('contributor_count') === 1 ? ' contributor' : ' contributors',
|
|
||||||
topic_count_number: '<span class="tCountColor">' + this.get('topic_count') + '</span>',
|
|
||||||
topic_count_string: this.get('topic_count') === 1 ? ' topic' : ' topics',
|
|
||||||
synapse_count_number: '<span class="sCountColor">' + this.get('synapse_count') + '</span>',
|
|
||||||
synapse_count_string: this.get('synapse_count') === 1 ? ' synapse' : ' synapses',
|
|
||||||
screenshot: '<img src="' + this.get('screenshot_url') + '" />'
|
|
||||||
}
|
|
||||||
return obj
|
|
||||||
},
|
|
||||||
updateView: function () {
|
|
||||||
var map = Metamaps.Active.Map
|
|
||||||
var isActiveMap = this.id === map.id
|
|
||||||
if (isActiveMap) {
|
|
||||||
Metamaps.Map.InfoBox.updateNameDescPerm(this.get('name'), this.get('desc'), this.get('permission'))
|
|
||||||
this.updateMapWrapper()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
updateMapWrapper: function () {
|
|
||||||
var map = Metamaps.Active.Map
|
|
||||||
var isActiveMap = this.id === map.id
|
|
||||||
var authorized = map && map.authorizeToEdit(Metamaps.Active.Mapper) ? 'canEditMap' : ''
|
|
||||||
var commonsMap = map && map.get('permission') === 'commons' ? 'commonsMap' : ''
|
|
||||||
if (isActiveMap) {
|
|
||||||
$('.wrapper').removeClass('canEditMap commonsMap').addClass(authorized + ' ' + commonsMap)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
Metamaps.Backbone.MapsCollection = Backbone.Collection.extend({
|
|
||||||
model: Metamaps.Backbone.Map,
|
|
||||||
initialize: function (models, options) {
|
|
||||||
this.id = options.id
|
|
||||||
this.sortBy = options.sortBy
|
|
||||||
|
|
||||||
if (options.mapperId) {
|
|
||||||
this.mapperId = options.mapperId
|
|
||||||
}
|
|
||||||
|
|
||||||
// this.page represents the NEXT page to fetch
|
|
||||||
this.page = models.length > 0 ? (models.length < 20 ? 'loadedAll' : 2) : 1
|
|
||||||
},
|
|
||||||
url: function () {
|
|
||||||
if (!this.mapperId) {
|
|
||||||
return '/explore/' + this.id + '.json'
|
|
||||||
} else {
|
|
||||||
return '/explore/mapper/' + this.mapperId + '.json'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
comparator: function (a, b) {
|
|
||||||
a = a.get(this.sortBy)
|
|
||||||
b = b.get(this.sortBy)
|
|
||||||
var temp
|
|
||||||
if (this.sortBy === 'name') {
|
|
||||||
a = a ? a.toLowerCase() : ''
|
|
||||||
b = b ? b.toLowerCase() : ''
|
|
||||||
} else {
|
|
||||||
// this is for updated_at and created_at
|
|
||||||
temp = a
|
|
||||||
a = b
|
|
||||||
b = temp
|
|
||||||
a = (new Date(a)).getTime()
|
|
||||||
b = (new Date(b)).getTime()
|
|
||||||
}
|
|
||||||
return a > b ? 1 : a < b ? -1 : 0
|
|
||||||
},
|
|
||||||
getMaps: function (cb) {
|
|
||||||
var self = this
|
|
||||||
|
|
||||||
Metamaps.Loading.show()
|
|
||||||
|
|
||||||
if (this.page !== 'loadedAll') {
|
|
||||||
var numBefore = this.length
|
|
||||||
this.fetch({
|
|
||||||
remove: false,
|
|
||||||
silent: true,
|
|
||||||
data: { page: this.page },
|
|
||||||
success: function (collection, response, options) {
|
|
||||||
// you can pass additional options to the event you trigger here as well
|
|
||||||
if (collection.length - numBefore < 20) {
|
|
||||||
self.page = 'loadedAll'
|
|
||||||
} else {
|
|
||||||
self.page += 1
|
|
||||||
}
|
|
||||||
self.trigger('successOnFetch', cb)
|
|
||||||
},
|
|
||||||
error: function (collection, response, options) {
|
|
||||||
// you can pass additional options to the event you trigger here as well
|
|
||||||
self.trigger('errorOnFetch')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
self.trigger('successOnFetch', cb)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
Metamaps.Backbone.Message = Backbone.Model.extend({
|
|
||||||
urlRoot: '/messages',
|
|
||||||
blacklist: ['created_at', 'updated_at'],
|
|
||||||
toJSON: function (options) {
|
|
||||||
return _.omit(this.attributes, this.blacklist)
|
|
||||||
},
|
|
||||||
prepareLiForFilter: function () {
|
|
||||||
/* var li = ''
|
|
||||||
* li += '<li data-id="' + this.id.toString() + '">'
|
|
||||||
* li += '<img src="' + this.get("image") + '" data-id="' + this.id.toString() + '"'
|
|
||||||
* li += ' alt="' + this.get('name') + '" />'
|
|
||||||
* li += '<p>' + this.get('name') + '</p></li>'
|
|
||||||
* return li
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
})
|
|
||||||
Metamaps.Backbone.MessageCollection = Backbone.Collection.extend({
|
|
||||||
model: Metamaps.Backbone.Message,
|
|
||||||
url: '/messages'
|
|
||||||
})
|
|
||||||
|
|
||||||
Metamaps.Backbone.Mapper = Backbone.Model.extend({
|
|
||||||
urlRoot: '/users',
|
|
||||||
blacklist: ['created_at', 'updated_at'],
|
|
||||||
toJSON: function (options) {
|
|
||||||
return _.omit(this.attributes, this.blacklist)
|
|
||||||
},
|
|
||||||
prepareLiForFilter: function () {
|
|
||||||
var li = ''
|
|
||||||
li += '<li data-id="' + this.id.toString() + '">'
|
|
||||||
li += '<img src="' + this.get('image') + '" data-id="' + this.id.toString() + '"'
|
|
||||||
li += ' alt="' + this.get('name') + '" />'
|
|
||||||
li += '<p>' + this.get('name') + '</p></li>'
|
|
||||||
return li
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
Metamaps.Backbone.MapperCollection = Backbone.Collection.extend({
|
|
||||||
model: Metamaps.Backbone.Mapper,
|
|
||||||
url: '/users'
|
|
||||||
})
|
|
437
app/assets/javascripts/src/Metamaps.Control.js
Normal file
437
app/assets/javascripts/src/Metamaps.Control.js
Normal file
|
@ -0,0 +1,437 @@
|
||||||
|
/* global Metamaps, $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Metamaps.Control.js.erb
|
||||||
|
*
|
||||||
|
* Dependencies:
|
||||||
|
* - Metamaps.Active
|
||||||
|
* - Metamaps.Control
|
||||||
|
* - Metamaps.Filter
|
||||||
|
* - Metamaps.GlobalUI
|
||||||
|
* - Metamaps.JIT
|
||||||
|
* - Metamaps.Mappings
|
||||||
|
* - Metamaps.Metacodes
|
||||||
|
* - Metamaps.Mouse
|
||||||
|
* - Metamaps.Selected
|
||||||
|
* - Metamaps.Settings
|
||||||
|
* - Metamaps.Synapses
|
||||||
|
* - Metamaps.Topics
|
||||||
|
* - Metamaps.Visualize
|
||||||
|
*/
|
||||||
|
|
||||||
|
Metamaps.Control = {
|
||||||
|
init: function () {},
|
||||||
|
selectNode: function (node, e) {
|
||||||
|
var filtered = node.getData('alpha') === 0
|
||||||
|
|
||||||
|
if (filtered || Metamaps.Selected.Nodes.indexOf(node) != -1) return
|
||||||
|
node.selected = true
|
||||||
|
node.setData('dim', 30, 'current')
|
||||||
|
Metamaps.Selected.Nodes.push(node)
|
||||||
|
},
|
||||||
|
deselectAllNodes: function () {
|
||||||
|
var l = Metamaps.Selected.Nodes.length
|
||||||
|
for (var i = l - 1; i >= 0; i -= 1) {
|
||||||
|
var node = Metamaps.Selected.Nodes[i]
|
||||||
|
Metamaps.Control.deselectNode(node)
|
||||||
|
}
|
||||||
|
Metamaps.Visualize.mGraph.plot()
|
||||||
|
},
|
||||||
|
deselectNode: function (node) {
|
||||||
|
delete node.selected
|
||||||
|
node.setData('dim', 25, 'current')
|
||||||
|
|
||||||
|
// remove the node
|
||||||
|
Metamaps.Selected.Nodes.splice(
|
||||||
|
Metamaps.Selected.Nodes.indexOf(node), 1)
|
||||||
|
},
|
||||||
|
deleteSelected: function () {
|
||||||
|
if (!Metamaps.Active.Map) return
|
||||||
|
|
||||||
|
var n = Metamaps.Selected.Nodes.length
|
||||||
|
var e = Metamaps.Selected.Edges.length
|
||||||
|
var ntext = n == 1 ? '1 topic' : n + ' topics'
|
||||||
|
var etext = e == 1 ? '1 synapse' : e + ' synapses'
|
||||||
|
var text = 'You have ' + ntext + ' and ' + etext + ' selected. '
|
||||||
|
|
||||||
|
var authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper)
|
||||||
|
|
||||||
|
if (!authorized) {
|
||||||
|
Metamaps.GlobalUI.notifyUser('Cannot edit Public map.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var r = confirm(text + 'Are you sure you want to permanently delete them all? This will remove them from all maps they appear on.')
|
||||||
|
if (r == true) {
|
||||||
|
Metamaps.Control.deleteSelectedEdges()
|
||||||
|
Metamaps.Control.deleteSelectedNodes()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
deleteSelectedNodes: function () { // refers to deleting topics permanently
|
||||||
|
if (!Metamaps.Active.Map) return
|
||||||
|
|
||||||
|
var authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper)
|
||||||
|
|
||||||
|
if (!authorized) {
|
||||||
|
Metamaps.GlobalUI.notifyUser('Cannot edit Public map.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var l = Metamaps.Selected.Nodes.length
|
||||||
|
for (var i = l - 1; i >= 0; i -= 1) {
|
||||||
|
var node = Metamaps.Selected.Nodes[i]
|
||||||
|
Metamaps.Control.deleteNode(node.id)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
deleteNode: function (nodeid) { // refers to deleting topics permanently
|
||||||
|
if (!Metamaps.Active.Map) return
|
||||||
|
|
||||||
|
var authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper)
|
||||||
|
|
||||||
|
if (!authorized) {
|
||||||
|
Metamaps.GlobalUI.notifyUser('Cannot edit Public map.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var node = Metamaps.Visualize.mGraph.graph.getNode(nodeid)
|
||||||
|
var topic = node.getData('topic')
|
||||||
|
|
||||||
|
var permToDelete = Metamaps.Active.Mapper.id === topic.get('user_id') || Metamaps.Active.Mapper.get('admin')
|
||||||
|
if (permToDelete) {
|
||||||
|
var mappableid = topic.id
|
||||||
|
var mapping = node.getData('mapping')
|
||||||
|
topic.destroy()
|
||||||
|
Metamaps.Mappings.remove(mapping)
|
||||||
|
$(document).trigger(Metamaps.JIT.events.deleteTopic, [{
|
||||||
|
mappableid: mappableid
|
||||||
|
}])
|
||||||
|
Metamaps.Control.hideNode(nodeid)
|
||||||
|
} else {
|
||||||
|
Metamaps.GlobalUI.notifyUser('Only topics you created can be deleted')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
removeSelectedNodes: function () { // refers to removing topics permanently from a map
|
||||||
|
if (!Metamaps.Active.Map) return
|
||||||
|
|
||||||
|
var l = Metamaps.Selected.Nodes.length,
|
||||||
|
i,
|
||||||
|
node,
|
||||||
|
authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper)
|
||||||
|
|
||||||
|
if (!authorized) {
|
||||||
|
Metamaps.GlobalUI.notifyUser('Cannot edit Public map.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = l - 1; i >= 0; i -= 1) {
|
||||||
|
node = Metamaps.Selected.Nodes[i]
|
||||||
|
Metamaps.Control.removeNode(node.id)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
removeNode: function (nodeid) { // refers to removing topics permanently from a map
|
||||||
|
if (!Metamaps.Active.Map) return
|
||||||
|
|
||||||
|
var authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper)
|
||||||
|
var node = Metamaps.Visualize.mGraph.graph.getNode(nodeid)
|
||||||
|
|
||||||
|
if (!authorized) {
|
||||||
|
Metamaps.GlobalUI.notifyUser('Cannot edit Public map.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var topic = node.getData('topic')
|
||||||
|
var mappableid = topic.id
|
||||||
|
var mapping = node.getData('mapping')
|
||||||
|
mapping.destroy()
|
||||||
|
Metamaps.Topics.remove(topic)
|
||||||
|
$(document).trigger(Metamaps.JIT.events.removeTopic, [{
|
||||||
|
mappableid: mappableid
|
||||||
|
}])
|
||||||
|
Metamaps.Control.hideNode(nodeid)
|
||||||
|
},
|
||||||
|
hideSelectedNodes: function () {
|
||||||
|
var l = Metamaps.Selected.Nodes.length,
|
||||||
|
i,
|
||||||
|
node
|
||||||
|
|
||||||
|
for (i = l - 1; i >= 0; i -= 1) {
|
||||||
|
node = Metamaps.Selected.Nodes[i]
|
||||||
|
Metamaps.Control.hideNode(node.id)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
hideNode: function (nodeid) {
|
||||||
|
var node = Metamaps.Visualize.mGraph.graph.getNode(nodeid)
|
||||||
|
var graph = Metamaps.Visualize.mGraph
|
||||||
|
|
||||||
|
Metamaps.Control.deselectNode(node)
|
||||||
|
|
||||||
|
node.setData('alpha', 0, 'end')
|
||||||
|
node.eachAdjacency(function (adj) {
|
||||||
|
adj.setData('alpha', 0, 'end')
|
||||||
|
})
|
||||||
|
Metamaps.Visualize.mGraph.fx.animate({
|
||||||
|
modes: ['node-property:alpha',
|
||||||
|
'edge-property:alpha'
|
||||||
|
],
|
||||||
|
duration: 500
|
||||||
|
})
|
||||||
|
setTimeout(function () {
|
||||||
|
if (nodeid == Metamaps.Visualize.mGraph.root) { // && Metamaps.Visualize.type === "RGraph"
|
||||||
|
var newroot = _.find(graph.graph.nodes, function (n) { return n.id !== nodeid; })
|
||||||
|
graph.root = newroot ? newroot.id : null
|
||||||
|
}
|
||||||
|
Metamaps.Visualize.mGraph.graph.removeNode(nodeid)
|
||||||
|
}, 500)
|
||||||
|
Metamaps.Filter.checkMetacodes()
|
||||||
|
Metamaps.Filter.checkMappers()
|
||||||
|
},
|
||||||
|
selectEdge: function (edge) {
|
||||||
|
var filtered = edge.getData('alpha') === 0; // don't select if the edge is filtered
|
||||||
|
|
||||||
|
if (filtered || Metamaps.Selected.Edges.indexOf(edge) != -1) return
|
||||||
|
|
||||||
|
var width = Metamaps.Mouse.edgeHoveringOver === edge ? 4 : 2
|
||||||
|
edge.setDataset('current', {
|
||||||
|
showDesc: true,
|
||||||
|
lineWidth: width,
|
||||||
|
color: Metamaps.Settings.colors.synapses.selected
|
||||||
|
})
|
||||||
|
Metamaps.Visualize.mGraph.plot()
|
||||||
|
|
||||||
|
Metamaps.Selected.Edges.push(edge)
|
||||||
|
},
|
||||||
|
deselectAllEdges: function () {
|
||||||
|
var l = Metamaps.Selected.Edges.length
|
||||||
|
for (var i = l - 1; i >= 0; i -= 1) {
|
||||||
|
var edge = Metamaps.Selected.Edges[i]
|
||||||
|
Metamaps.Control.deselectEdge(edge)
|
||||||
|
}
|
||||||
|
Metamaps.Visualize.mGraph.plot()
|
||||||
|
},
|
||||||
|
deselectEdge: function (edge) {
|
||||||
|
edge.setData('showDesc', false, 'current')
|
||||||
|
|
||||||
|
edge.setDataset('current', {
|
||||||
|
lineWidth: 2,
|
||||||
|
color: Metamaps.Settings.colors.synapses.normal
|
||||||
|
})
|
||||||
|
|
||||||
|
if (Metamaps.Mouse.edgeHoveringOver == edge) {
|
||||||
|
edge.setDataset('current', {
|
||||||
|
showDesc: true,
|
||||||
|
lineWidth: 4
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
Metamaps.Visualize.mGraph.plot()
|
||||||
|
|
||||||
|
// remove the edge
|
||||||
|
Metamaps.Selected.Edges.splice(
|
||||||
|
Metamaps.Selected.Edges.indexOf(edge), 1)
|
||||||
|
},
|
||||||
|
deleteSelectedEdges: function () { // refers to deleting topics permanently
|
||||||
|
var edge,
|
||||||
|
l = Metamaps.Selected.Edges.length
|
||||||
|
|
||||||
|
if (!Metamaps.Active.Map) return
|
||||||
|
|
||||||
|
var authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper)
|
||||||
|
|
||||||
|
if (!authorized) {
|
||||||
|
Metamaps.GlobalUI.notifyUser('Cannot edit Public map.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = l - 1; i >= 0; i -= 1) {
|
||||||
|
edge = Metamaps.Selected.Edges[i]
|
||||||
|
Metamaps.Control.deleteEdge(edge)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
deleteEdge: function (edge) {
|
||||||
|
if (!Metamaps.Active.Map) return
|
||||||
|
|
||||||
|
var authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper)
|
||||||
|
|
||||||
|
if (!authorized) {
|
||||||
|
Metamaps.GlobalUI.notifyUser('Cannot edit Public map.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var index = edge.getData('displayIndex') ? edge.getData('displayIndex') : 0
|
||||||
|
|
||||||
|
var synapse = edge.getData('synapses')[index]
|
||||||
|
var mapping = edge.getData('mappings')[index]
|
||||||
|
|
||||||
|
var permToDelete = Metamaps.Active.Mapper.id === synapse.get('user_id') || Metamaps.Active.Mapper.get('admin')
|
||||||
|
if (permToDelete) {
|
||||||
|
if (edge.getData('synapses').length - 1 === 0) {
|
||||||
|
Metamaps.Control.hideEdge(edge)
|
||||||
|
}
|
||||||
|
var mappableid = synapse.id
|
||||||
|
synapse.destroy()
|
||||||
|
|
||||||
|
// the server will destroy the mapping, we just need to remove it here
|
||||||
|
Metamaps.Mappings.remove(mapping)
|
||||||
|
edge.getData('mappings').splice(index, 1)
|
||||||
|
edge.getData('synapses').splice(index, 1)
|
||||||
|
if (edge.getData('displayIndex')) {
|
||||||
|
delete edge.data.$displayIndex
|
||||||
|
}
|
||||||
|
$(document).trigger(Metamaps.JIT.events.deleteSynapse, [{
|
||||||
|
mappableid: mappableid
|
||||||
|
}])
|
||||||
|
} else {
|
||||||
|
Metamaps.GlobalUI.notifyUser('Only synapses you created can be deleted')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
removeSelectedEdges: function () {
|
||||||
|
var l = Metamaps.Selected.Edges.length,
|
||||||
|
i,
|
||||||
|
edge
|
||||||
|
|
||||||
|
if (!Metamaps.Active.Map) return
|
||||||
|
|
||||||
|
var authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper)
|
||||||
|
|
||||||
|
if (!authorized) {
|
||||||
|
Metamaps.GlobalUI.notifyUser('Cannot edit Public map.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = l - 1; i >= 0; i -= 1) {
|
||||||
|
edge = Metamaps.Selected.Edges[i]
|
||||||
|
Metamaps.Control.removeEdge(edge)
|
||||||
|
}
|
||||||
|
Metamaps.Selected.Edges = [ ]
|
||||||
|
},
|
||||||
|
removeEdge: function (edge) {
|
||||||
|
if (!Metamaps.Active.Map) return
|
||||||
|
|
||||||
|
var authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper)
|
||||||
|
|
||||||
|
if (!authorized) {
|
||||||
|
Metamaps.GlobalUI.notifyUser('Cannot edit Public map.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (edge.getData('mappings').length - 1 === 0) {
|
||||||
|
Metamaps.Control.hideEdge(edge)
|
||||||
|
}
|
||||||
|
|
||||||
|
var index = edge.getData('displayIndex') ? edge.getData('displayIndex') : 0
|
||||||
|
|
||||||
|
var synapse = edge.getData('synapses')[index]
|
||||||
|
var mapping = edge.getData('mappings')[index]
|
||||||
|
var mappableid = synapse.id
|
||||||
|
mapping.destroy()
|
||||||
|
|
||||||
|
Metamaps.Synapses.remove(synapse)
|
||||||
|
|
||||||
|
edge.getData('mappings').splice(index, 1)
|
||||||
|
edge.getData('synapses').splice(index, 1)
|
||||||
|
if (edge.getData('displayIndex')) {
|
||||||
|
delete edge.data.$displayIndex
|
||||||
|
}
|
||||||
|
$(document).trigger(Metamaps.JIT.events.removeSynapse, [{
|
||||||
|
mappableid: mappableid
|
||||||
|
}])
|
||||||
|
},
|
||||||
|
hideSelectedEdges: function () {
|
||||||
|
var edge,
|
||||||
|
l = Metamaps.Selected.Edges.length,
|
||||||
|
i
|
||||||
|
for (i = l - 1; i >= 0; i -= 1) {
|
||||||
|
edge = Metamaps.Selected.Edges[i]
|
||||||
|
Metamaps.Control.hideEdge(edge)
|
||||||
|
}
|
||||||
|
Metamaps.Selected.Edges = [ ]
|
||||||
|
},
|
||||||
|
hideEdge: function (edge) {
|
||||||
|
var from = edge.nodeFrom.id
|
||||||
|
var to = edge.nodeTo.id
|
||||||
|
edge.setData('alpha', 0, 'end')
|
||||||
|
Metamaps.Control.deselectEdge(edge)
|
||||||
|
Metamaps.Visualize.mGraph.fx.animate({
|
||||||
|
modes: ['edge-property:alpha'],
|
||||||
|
duration: 500
|
||||||
|
})
|
||||||
|
setTimeout(function () {
|
||||||
|
Metamaps.Visualize.mGraph.graph.removeAdjacence(from, to)
|
||||||
|
}, 500)
|
||||||
|
Metamaps.Filter.checkSynapses()
|
||||||
|
Metamaps.Filter.checkMappers()
|
||||||
|
},
|
||||||
|
updateSelectedPermissions: function (permission) {
|
||||||
|
var edge, synapse, node, topic
|
||||||
|
|
||||||
|
Metamaps.GlobalUI.notifyUser('Working...')
|
||||||
|
|
||||||
|
// variables to keep track of how many nodes and synapses you had the ability to change the permission of
|
||||||
|
var nCount = 0,
|
||||||
|
sCount = 0
|
||||||
|
|
||||||
|
// change the permission of the selected synapses, if logged in user is the original creator
|
||||||
|
var l = Metamaps.Selected.Edges.length
|
||||||
|
for (var i = l - 1; i >= 0; i -= 1) {
|
||||||
|
edge = Metamaps.Selected.Edges[i]
|
||||||
|
synapse = edge.getData('synapses')[0]
|
||||||
|
|
||||||
|
if (synapse.authorizePermissionChange(Metamaps.Active.Mapper)) {
|
||||||
|
synapse.save({
|
||||||
|
permission: permission
|
||||||
|
})
|
||||||
|
sCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// change the permission of the selected topics, if logged in user is the original creator
|
||||||
|
var l = Metamaps.Selected.Nodes.length
|
||||||
|
for (var i = l - 1; i >= 0; i -= 1) {
|
||||||
|
node = Metamaps.Selected.Nodes[i]
|
||||||
|
topic = node.getData('topic')
|
||||||
|
|
||||||
|
if (topic.authorizePermissionChange(Metamaps.Active.Mapper)) {
|
||||||
|
topic.save({
|
||||||
|
permission: permission
|
||||||
|
})
|
||||||
|
nCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var nString = nCount == 1 ? (nCount.toString() + ' topic and ') : (nCount.toString() + ' topics and ')
|
||||||
|
var sString = sCount == 1 ? (sCount.toString() + ' synapse') : (sCount.toString() + ' synapses')
|
||||||
|
|
||||||
|
var message = nString + sString + ' you created updated to ' + permission
|
||||||
|
Metamaps.GlobalUI.notifyUser(message)
|
||||||
|
},
|
||||||
|
updateSelectedMetacodes: function (metacode_id) {
|
||||||
|
var node, topic
|
||||||
|
|
||||||
|
Metamaps.GlobalUI.notifyUser('Working...')
|
||||||
|
|
||||||
|
var metacode = Metamaps.Metacodes.get(metacode_id)
|
||||||
|
|
||||||
|
// variables to keep track of how many nodes and synapses you had the ability to change the permission of
|
||||||
|
var nCount = 0
|
||||||
|
|
||||||
|
// change the permission of the selected topics, if logged in user is the original creator
|
||||||
|
var l = Metamaps.Selected.Nodes.length
|
||||||
|
for (var i = l - 1; i >= 0; i -= 1) {
|
||||||
|
node = Metamaps.Selected.Nodes[i]
|
||||||
|
topic = node.getData('topic')
|
||||||
|
|
||||||
|
if (topic.authorizeToEdit(Metamaps.Active.Mapper)) {
|
||||||
|
topic.save({
|
||||||
|
'metacode_id': metacode_id
|
||||||
|
})
|
||||||
|
nCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var nString = nCount == 1 ? (nCount.toString() + ' topic') : (nCount.toString() + ' topics')
|
||||||
|
|
||||||
|
var message = nString + ' you can edit updated to ' + metacode.get('name')
|
||||||
|
Metamaps.GlobalUI.notifyUser(message)
|
||||||
|
Metamaps.Visualize.mGraph.plot()
|
||||||
|
},
|
||||||
|
}; // end Metamaps.Control
|
326
app/assets/javascripts/src/Metamaps.Create.js
Normal file
326
app/assets/javascripts/src/Metamaps.Create.js
Normal file
|
@ -0,0 +1,326 @@
|
||||||
|
/* global Metamaps, $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Metamaps.Create.js
|
||||||
|
*
|
||||||
|
* Dependencies:
|
||||||
|
* - Metamaps.Backbone
|
||||||
|
* - Metamaps.GlobalUI
|
||||||
|
* - Metamaps.Metacodes
|
||||||
|
* - Metamaps.Mouse
|
||||||
|
* - Metamaps.Selected
|
||||||
|
* - Metamaps.Synapse
|
||||||
|
* - Metamaps.Topic
|
||||||
|
* - Metamaps.Visualize
|
||||||
|
*/
|
||||||
|
|
||||||
|
Metamaps.Create = {
|
||||||
|
isSwitchingSet: false, // indicates whether the metacode set switch lightbox is open
|
||||||
|
selectedMetacodeSet: null,
|
||||||
|
selectedMetacodeSetIndex: null,
|
||||||
|
selectedMetacodeNames: [],
|
||||||
|
newSelectedMetacodeNames: [],
|
||||||
|
selectedMetacodes: [],
|
||||||
|
newSelectedMetacodes: [],
|
||||||
|
init: function () {
|
||||||
|
var self = Metamaps.Create
|
||||||
|
self.newTopic.init()
|
||||||
|
self.newSynapse.init()
|
||||||
|
|
||||||
|
// // SWITCHING METACODE SETS
|
||||||
|
|
||||||
|
$('#metacodeSwitchTabs').tabs({
|
||||||
|
selected: self.selectedMetacodeSetIndex
|
||||||
|
}).addClass('ui-tabs-vertical ui-helper-clearfix')
|
||||||
|
$('#metacodeSwitchTabs .ui-tabs-nav li').removeClass('ui-corner-top').addClass('ui-corner-left')
|
||||||
|
$('.customMetacodeList li').click(self.toggleMetacodeSelected) // within the custom metacode set tab
|
||||||
|
},
|
||||||
|
toggleMetacodeSelected: function () {
|
||||||
|
var self = Metamaps.Create
|
||||||
|
|
||||||
|
if ($(this).attr('class') != 'toggledOff') {
|
||||||
|
$(this).addClass('toggledOff')
|
||||||
|
var value_to_remove = $(this).attr('id')
|
||||||
|
var name_to_remove = $(this).attr('data-name')
|
||||||
|
self.newSelectedMetacodes.splice(self.newSelectedMetacodes.indexOf(value_to_remove), 1)
|
||||||
|
self.newSelectedMetacodeNames.splice(self.newSelectedMetacodeNames.indexOf(name_to_remove), 1)
|
||||||
|
} else if ($(this).attr('class') == 'toggledOff') {
|
||||||
|
$(this).removeClass('toggledOff')
|
||||||
|
self.newSelectedMetacodes.push($(this).attr('id'))
|
||||||
|
self.newSelectedMetacodeNames.push($(this).attr('data-name'))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateMetacodeSet: function (set, index, custom) {
|
||||||
|
if (custom && Metamaps.Create.newSelectedMetacodes.length == 0) {
|
||||||
|
alert('Please select at least one metacode to use!')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var codesToSwitchToIds
|
||||||
|
var metacodeModels = new Metamaps.Backbone.MetacodeCollection()
|
||||||
|
Metamaps.Create.selectedMetacodeSetIndex = index
|
||||||
|
Metamaps.Create.selectedMetacodeSet = 'metacodeset-' + set
|
||||||
|
|
||||||
|
if (!custom) {
|
||||||
|
codesToSwitchToIds = $('#metacodeSwitchTabs' + set).attr('data-metacodes').split(',')
|
||||||
|
$('.customMetacodeList li').addClass('toggledOff')
|
||||||
|
Metamaps.Create.selectedMetacodes = []
|
||||||
|
Metamaps.Create.selectedMetacodeNames = []
|
||||||
|
Metamaps.Create.newSelectedMetacodes = []
|
||||||
|
Metamaps.Create.newSelectedMetacodeNames = []
|
||||||
|
}
|
||||||
|
else if (custom) {
|
||||||
|
// uses .slice to avoid setting the two arrays to the same actual array
|
||||||
|
Metamaps.Create.selectedMetacodes = Metamaps.Create.newSelectedMetacodes.slice(0)
|
||||||
|
Metamaps.Create.selectedMetacodeNames = Metamaps.Create.newSelectedMetacodeNames.slice(0)
|
||||||
|
codesToSwitchToIds = Metamaps.Create.selectedMetacodes.slice(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// sort by name
|
||||||
|
for (var i = 0; i < codesToSwitchToIds.length; i++) {
|
||||||
|
metacodeModels.add(Metamaps.Metacodes.get(codesToSwitchToIds[i]))
|
||||||
|
}
|
||||||
|
metacodeModels.sort()
|
||||||
|
|
||||||
|
$('#metacodeImg, #metacodeImgTitle').empty()
|
||||||
|
$('#metacodeImg').removeData('cloudcarousel')
|
||||||
|
var newMetacodes = ''
|
||||||
|
metacodeModels.each(function (metacode) {
|
||||||
|
newMetacodes += '<img class="cloudcarousel" width="40" height="40" src="' + metacode.get('icon') + '" data-id="' + metacode.id + '" title="' + metacode.get('name') + '" alt="' + metacode.get('name') + '"/>'
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#metacodeImg').empty().append(newMetacodes).CloudCarousel({
|
||||||
|
titleBox: $('#metacodeImgTitle'),
|
||||||
|
yRadius: 40,
|
||||||
|
xRadius: 190,
|
||||||
|
xPos: 170,
|
||||||
|
yPos: 40,
|
||||||
|
speed: 0.3,
|
||||||
|
mouseWheel: true,
|
||||||
|
bringToFront: true
|
||||||
|
})
|
||||||
|
|
||||||
|
Metamaps.GlobalUI.closeLightbox()
|
||||||
|
$('#topic_name').focus()
|
||||||
|
|
||||||
|
var mdata = {
|
||||||
|
'metacodes': {
|
||||||
|
'value': custom ? Metamaps.Create.selectedMetacodes.toString() : Metamaps.Create.selectedMetacodeSet
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
url: '/user/updatemetacodes',
|
||||||
|
data: mdata,
|
||||||
|
success: function (data) {
|
||||||
|
console.log('selected metacodes saved')
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
console.log('failed to save selected metacodes')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
cancelMetacodeSetSwitch: function () {
|
||||||
|
var self = Metamaps.Create
|
||||||
|
self.isSwitchingSet = false
|
||||||
|
|
||||||
|
if (self.selectedMetacodeSet != 'metacodeset-custom') {
|
||||||
|
$('.customMetacodeList li').addClass('toggledOff')
|
||||||
|
self.selectedMetacodes = []
|
||||||
|
self.selectedMetacodeNames = []
|
||||||
|
self.newSelectedMetacodes = []
|
||||||
|
self.newSelectedMetacodeNames = []
|
||||||
|
} else { // custom set is selected
|
||||||
|
// reset it to the current actual selection
|
||||||
|
$('.customMetacodeList li').addClass('toggledOff')
|
||||||
|
for (var i = 0; i < self.selectedMetacodes.length; i++) {
|
||||||
|
$('#' + self.selectedMetacodes[i]).removeClass('toggledOff')
|
||||||
|
}
|
||||||
|
// uses .slice to avoid setting the two arrays to the same actual array
|
||||||
|
self.newSelectedMetacodeNames = self.selectedMetacodeNames.slice(0)
|
||||||
|
self.newSelectedMetacodes = self.selectedMetacodes.slice(0)
|
||||||
|
}
|
||||||
|
$('#metacodeSwitchTabs').tabs('option', 'active', self.selectedMetacodeSetIndex)
|
||||||
|
$('#topic_name').focus()
|
||||||
|
},
|
||||||
|
newTopic: {
|
||||||
|
init: function () {
|
||||||
|
$('#topic_name').keyup(function () {
|
||||||
|
Metamaps.Create.newTopic.name = $(this).val()
|
||||||
|
})
|
||||||
|
|
||||||
|
var topicBloodhound = new Bloodhound({
|
||||||
|
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
|
||||||
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||||
|
remote: {
|
||||||
|
url: '/topics/autocomplete_topic?term=%QUERY',
|
||||||
|
wildcard: '%QUERY',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// initialize the autocomplete results for the metacode spinner
|
||||||
|
$('#topic_name').typeahead(
|
||||||
|
{
|
||||||
|
highlight: true,
|
||||||
|
minLength: 2,
|
||||||
|
},
|
||||||
|
[{
|
||||||
|
name: 'topic_autocomplete',
|
||||||
|
limit: 8,
|
||||||
|
display: function (s) { return s.label; },
|
||||||
|
templates: {
|
||||||
|
suggestion: function (s) {
|
||||||
|
return Hogan.compile($('#topicAutocompleteTemplate').html()).render(s)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
source: topicBloodhound,
|
||||||
|
}]
|
||||||
|
)
|
||||||
|
|
||||||
|
// tell the autocomplete to submit the form with the topic you clicked on if you pick from the autocomplete
|
||||||
|
$('#topic_name').bind('typeahead:select', function (event, datum, dataset) {
|
||||||
|
Metamaps.Topic.getTopicFromAutocomplete(datum.id)
|
||||||
|
})
|
||||||
|
|
||||||
|
// initialize metacode spinner and then hide it
|
||||||
|
$('#metacodeImg').CloudCarousel({
|
||||||
|
titleBox: $('#metacodeImgTitle'),
|
||||||
|
yRadius: 40,
|
||||||
|
xRadius: 190,
|
||||||
|
xPos: 170,
|
||||||
|
yPos: 40,
|
||||||
|
speed: 0.3,
|
||||||
|
mouseWheel: true,
|
||||||
|
bringToFront: true
|
||||||
|
})
|
||||||
|
$('.new_topic').hide()
|
||||||
|
},
|
||||||
|
name: null,
|
||||||
|
newId: 1,
|
||||||
|
beingCreated: false,
|
||||||
|
metacode: null,
|
||||||
|
x: null,
|
||||||
|
y: null,
|
||||||
|
addSynapse: false,
|
||||||
|
open: function () {
|
||||||
|
$('#new_topic').fadeIn('fast', function () {
|
||||||
|
$('#topic_name').focus()
|
||||||
|
})
|
||||||
|
Metamaps.Create.newTopic.beingCreated = true
|
||||||
|
Metamaps.Create.newTopic.name = ''
|
||||||
|
},
|
||||||
|
hide: function () {
|
||||||
|
$('#new_topic').fadeOut('fast')
|
||||||
|
$('#topic_name').typeahead('val', '')
|
||||||
|
Metamaps.Create.newTopic.beingCreated = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
newSynapse: {
|
||||||
|
init: function () {
|
||||||
|
var self = Metamaps.Create.newSynapse
|
||||||
|
|
||||||
|
var synapseBloodhound = new Bloodhound({
|
||||||
|
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
|
||||||
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||||
|
remote: {
|
||||||
|
url: '/search/synapses?term=%QUERY',
|
||||||
|
wildcard: '%QUERY',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
var existingSynapseBloodhound = new Bloodhound({
|
||||||
|
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
|
||||||
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||||
|
remote: {
|
||||||
|
url: '/search/synapses?topic1id=%TOPIC1&topic2id=%TOPIC2',
|
||||||
|
prepare: function (query, settings) {
|
||||||
|
var self = Metamaps.Create.newSynapse
|
||||||
|
if (Metamaps.Selected.Nodes.length < 2) {
|
||||||
|
settings.url = settings.url.replace('%TOPIC1', self.topic1id).replace('%TOPIC2', self.topic2id)
|
||||||
|
return settings
|
||||||
|
} else {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// initialize the autocomplete results for synapse creation
|
||||||
|
$('#synapse_desc').typeahead(
|
||||||
|
{
|
||||||
|
highlight: true,
|
||||||
|
minLength: 2,
|
||||||
|
},
|
||||||
|
[{
|
||||||
|
name: 'synapse_autocomplete',
|
||||||
|
display: function (s) { return s.label; },
|
||||||
|
templates: {
|
||||||
|
suggestion: function (s) {
|
||||||
|
return Hogan.compile("<div class='genericSynapseDesc'>{{label}}</div>").render(s)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
source: synapseBloodhound,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'existing_synapses',
|
||||||
|
limit: 50,
|
||||||
|
display: function (s) { return s.label; },
|
||||||
|
templates: {
|
||||||
|
suggestion: function (s) {
|
||||||
|
return Hogan.compile($('#synapseAutocompleteTemplate').html()).render(s)
|
||||||
|
},
|
||||||
|
header: '<h3>Existing synapses</h3>'
|
||||||
|
},
|
||||||
|
source: existingSynapseBloodhound,
|
||||||
|
}]
|
||||||
|
)
|
||||||
|
|
||||||
|
$('#synapse_desc').keyup(function (e) {
|
||||||
|
var ESC = 27, BACKSPACE = 8, DELETE = 46
|
||||||
|
if (e.keyCode === BACKSPACE && $(this).val() === '' ||
|
||||||
|
e.keyCode === DELETE && $(this).val() === '' ||
|
||||||
|
e.keyCode === ESC) {
|
||||||
|
Metamaps.Create.newSynapse.hide()
|
||||||
|
} // if
|
||||||
|
Metamaps.Create.newSynapse.description = $(this).val()
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#synapse_desc').focusout(function () {
|
||||||
|
if (Metamaps.Create.newSynapse.beingCreated) {
|
||||||
|
Metamaps.Synapse.createSynapseLocally()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#synapse_desc').bind('typeahead:select', function (event, datum, dataset) {
|
||||||
|
if (datum.id) { // if they clicked on an existing synapse get it
|
||||||
|
Metamaps.Synapse.getSynapseFromAutocomplete(datum.id)
|
||||||
|
} else {
|
||||||
|
Metamaps.Create.newSynapse.description = datum.value
|
||||||
|
Metamaps.Synapse.createSynapseLocally()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
beingCreated: false,
|
||||||
|
description: null,
|
||||||
|
topic1id: null,
|
||||||
|
topic2id: null,
|
||||||
|
newSynapseId: null,
|
||||||
|
open: function () {
|
||||||
|
$('#new_synapse').fadeIn(100, function () {
|
||||||
|
$('#synapse_desc').focus()
|
||||||
|
})
|
||||||
|
Metamaps.Create.newSynapse.beingCreated = true
|
||||||
|
},
|
||||||
|
hide: function () {
|
||||||
|
$('#new_synapse').fadeOut('fast')
|
||||||
|
$('#synapse_desc').typeahead('val', '')
|
||||||
|
Metamaps.Create.newSynapse.beingCreated = false
|
||||||
|
Metamaps.Create.newTopic.addSynapse = false
|
||||||
|
Metamaps.Create.newSynapse.topic1id = 0
|
||||||
|
Metamaps.Create.newSynapse.topic2id = 0
|
||||||
|
Metamaps.Mouse.synapseStartCoordinates = []
|
||||||
|
Metamaps.Visualize.mGraph.plot()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}; // end Metamaps.Create
|
466
app/assets/javascripts/src/Metamaps.Filter.js
Normal file
466
app/assets/javascripts/src/Metamaps.Filter.js
Normal file
|
@ -0,0 +1,466 @@
|
||||||
|
/* global Metamaps, $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Metamaps.Filter.js.erb
|
||||||
|
*
|
||||||
|
* Dependencies:
|
||||||
|
* - Metamaps.Active
|
||||||
|
* - Metamaps.Control
|
||||||
|
* - Metamaps.Creators
|
||||||
|
* - Metamaps.GlobalUI
|
||||||
|
* - Metamaps.Mappers
|
||||||
|
* - Metamaps.Metacodes
|
||||||
|
* - Metamaps.Settings
|
||||||
|
* - Metamaps.Synapses
|
||||||
|
* - Metamaps.Topics
|
||||||
|
* - Metamaps.Visualize
|
||||||
|
*/
|
||||||
|
Metamaps.Filter = {
|
||||||
|
filters: {
|
||||||
|
name: '',
|
||||||
|
metacodes: [],
|
||||||
|
mappers: [],
|
||||||
|
synapses: []
|
||||||
|
},
|
||||||
|
visible: {
|
||||||
|
metacodes: [],
|
||||||
|
mappers: [],
|
||||||
|
synapses: []
|
||||||
|
},
|
||||||
|
isOpen: false,
|
||||||
|
changing: false,
|
||||||
|
init: function () {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
|
||||||
|
$('.sidebarFilterIcon').click(self.toggleBox)
|
||||||
|
|
||||||
|
$('.sidebarFilterBox .showAllMetacodes').click(self.filterNoMetacodes)
|
||||||
|
$('.sidebarFilterBox .showAllSynapses').click(self.filterNoSynapses)
|
||||||
|
$('.sidebarFilterBox .showAllMappers').click(self.filterNoMappers)
|
||||||
|
$('.sidebarFilterBox .hideAllMetacodes').click(self.filterAllMetacodes)
|
||||||
|
$('.sidebarFilterBox .hideAllSynapses').click(self.filterAllSynapses)
|
||||||
|
$('.sidebarFilterBox .hideAllMappers').click(self.filterAllMappers)
|
||||||
|
|
||||||
|
self.bindLiClicks()
|
||||||
|
self.getFilterData()
|
||||||
|
},
|
||||||
|
toggleBox: function (event) {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
|
||||||
|
if (self.isOpen) self.close()
|
||||||
|
else self.open()
|
||||||
|
|
||||||
|
event.stopPropagation()
|
||||||
|
},
|
||||||
|
open: function () {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
|
||||||
|
Metamaps.GlobalUI.Account.close()
|
||||||
|
$('.sidebarFilterIcon div').addClass('hide')
|
||||||
|
|
||||||
|
if (!self.isOpen && !self.changing) {
|
||||||
|
self.changing = true
|
||||||
|
|
||||||
|
var height = $(document).height() - 108
|
||||||
|
$('.sidebarFilterBox').css('max-height', height + 'px').fadeIn(200, function () {
|
||||||
|
self.changing = false
|
||||||
|
self.isOpen = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
close: function () {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
$('.sidebarFilterIcon div').removeClass('hide')
|
||||||
|
|
||||||
|
if (!self.changing) {
|
||||||
|
self.changing = true
|
||||||
|
|
||||||
|
$('.sidebarFilterBox').fadeOut(200, function () {
|
||||||
|
self.changing = false
|
||||||
|
self.isOpen = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
reset: function () {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
|
||||||
|
self.filters.metacodes = []
|
||||||
|
self.filters.mappers = []
|
||||||
|
self.filters.synapses = []
|
||||||
|
self.visible.metacodes = []
|
||||||
|
self.visible.mappers = []
|
||||||
|
self.visible.synapses = []
|
||||||
|
|
||||||
|
$('#filter_by_metacode ul').empty()
|
||||||
|
$('#filter_by_mapper ul').empty()
|
||||||
|
$('#filter_by_synapse ul').empty()
|
||||||
|
|
||||||
|
$('.filterBox .showAll').addClass('active')
|
||||||
|
},
|
||||||
|
/*
|
||||||
|
Most of this data essentially depends on the ruby function which are happening for filter inside view filterBox
|
||||||
|
But what these function do is load this data into three accessible array within java : metacodes, mappers and synapses
|
||||||
|
*/
|
||||||
|
getFilterData: function () {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
|
||||||
|
var metacode, mapper, synapse
|
||||||
|
|
||||||
|
$('#filter_by_metacode li').each(function () {
|
||||||
|
metacode = $(this).attr('data-id')
|
||||||
|
self.filters.metacodes.push(metacode)
|
||||||
|
self.visible.metacodes.push(metacode)
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#filter_by_mapper li').each(function () {
|
||||||
|
mapper = ($(this).attr('data-id'))
|
||||||
|
self.filters.mappers.push(mapper)
|
||||||
|
self.visible.mappers.push(mapper)
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#filter_by_synapse li').each(function () {
|
||||||
|
synapse = ($(this).attr('data-id'))
|
||||||
|
self.filters.synapses.push(synapse)
|
||||||
|
self.visible.synapses.push(synapse)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
bindLiClicks: function () {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
$('#filter_by_metacode ul li').unbind().click(self.toggleMetacode)
|
||||||
|
$('#filter_by_mapper ul li').unbind().click(self.toggleMapper)
|
||||||
|
$('#filter_by_synapse ul li').unbind().click(self.toggleSynapse)
|
||||||
|
},
|
||||||
|
// an abstraction function for checkMetacodes, checkMappers, checkSynapses to reduce
|
||||||
|
// code redundancy
|
||||||
|
/*
|
||||||
|
@param
|
||||||
|
*/
|
||||||
|
updateFilters: function (collection, propertyToCheck, correlatedModel, filtersToUse, listToModify) {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
|
||||||
|
var newList = []
|
||||||
|
var removed = []
|
||||||
|
var added = []
|
||||||
|
|
||||||
|
// the first option enables us to accept
|
||||||
|
// ['Topics', 'Synapses'] as 'collection'
|
||||||
|
if (typeof collection === 'object') {
|
||||||
|
Metamaps[collection[0]].each(function (model) {
|
||||||
|
var prop = model.get(propertyToCheck)
|
||||||
|
if (prop !== null) {
|
||||||
|
prop = prop.toString()
|
||||||
|
if (newList.indexOf(prop) === -1) {
|
||||||
|
newList.push(prop)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Metamaps[collection[1]].each(function (model) {
|
||||||
|
var prop = model.get(propertyToCheck)
|
||||||
|
if (prop !== null) {
|
||||||
|
prop = prop.toString()
|
||||||
|
if (newList.indexOf(prop) === -1) {
|
||||||
|
newList.push(prop)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else if (typeof collection === 'string') {
|
||||||
|
Metamaps[collection].each(function (model) {
|
||||||
|
var prop = model.get(propertyToCheck)
|
||||||
|
if (prop !== null) {
|
||||||
|
prop = prop.toString()
|
||||||
|
if (newList.indexOf(prop) === -1) {
|
||||||
|
newList.push(prop)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
removed = _.difference(self.filters[filtersToUse], newList)
|
||||||
|
added = _.difference(newList, self.filters[filtersToUse])
|
||||||
|
|
||||||
|
// remove the list items for things no longer present on the map
|
||||||
|
_.each(removed, function (identifier) {
|
||||||
|
$('#filter_by_' + listToModify + ' li[data-id="' + identifier + '"]').fadeOut('fast', function () {
|
||||||
|
$(this).remove()
|
||||||
|
})
|
||||||
|
index = self.visible[filtersToUse].indexOf(identifier)
|
||||||
|
self.visible[filtersToUse].splice(index, 1)
|
||||||
|
})
|
||||||
|
|
||||||
|
var model, li, jQueryLi
|
||||||
|
function sortAlpha (a, b) {
|
||||||
|
return a.childNodes[1].innerHTML.toLowerCase() > b.childNodes[1].innerHTML.toLowerCase() ? 1 : -1
|
||||||
|
}
|
||||||
|
// for each new filter to be added, create a list item for it and fade it in
|
||||||
|
_.each(added, function (identifier) {
|
||||||
|
model = Metamaps[correlatedModel].get(identifier) ||
|
||||||
|
Metamaps[correlatedModel].find(function (model) {
|
||||||
|
return model.get(propertyToCheck) === identifier
|
||||||
|
})
|
||||||
|
li = model.prepareLiForFilter()
|
||||||
|
jQueryLi = $(li).hide()
|
||||||
|
$('li', '#filter_by_' + listToModify + ' ul').add(jQueryLi.fadeIn('fast'))
|
||||||
|
.sort(sortAlpha).appendTo('#filter_by_' + listToModify + ' ul')
|
||||||
|
self.visible[filtersToUse].push(identifier)
|
||||||
|
})
|
||||||
|
|
||||||
|
// update the list of filters with the new list we just generated
|
||||||
|
self.filters[filtersToUse] = newList
|
||||||
|
|
||||||
|
// make sure clicks on list items still trigger the right events
|
||||||
|
self.bindLiClicks()
|
||||||
|
},
|
||||||
|
checkMetacodes: function () {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
self.updateFilters('Topics', 'metacode_id', 'Metacodes', 'metacodes', 'metacode')
|
||||||
|
},
|
||||||
|
checkMappers: function () {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
var onMap = Metamaps.Active.Map ? true : false
|
||||||
|
if (onMap) {
|
||||||
|
self.updateFilters('Mappings', 'user_id', 'Mappers', 'mappers', 'mapper')
|
||||||
|
} else {
|
||||||
|
// on topic view
|
||||||
|
self.updateFilters(['Topics', 'Synapses'], 'user_id', 'Creators', 'mappers', 'mapper')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
checkSynapses: function () {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
self.updateFilters('Synapses', 'desc', 'Synapses', 'synapses', 'synapse')
|
||||||
|
},
|
||||||
|
filterAllMetacodes: function (e) {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
$('#filter_by_metacode ul li').addClass('toggledOff')
|
||||||
|
$('.showAllMetacodes').removeClass('active')
|
||||||
|
$('.hideAllMetacodes').addClass('active')
|
||||||
|
self.visible.metacodes = []
|
||||||
|
self.passFilters()
|
||||||
|
},
|
||||||
|
filterNoMetacodes: function (e) {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
$('#filter_by_metacode ul li').removeClass('toggledOff')
|
||||||
|
$('.showAllMetacodes').addClass('active')
|
||||||
|
$('.hideAllMetacodes').removeClass('active')
|
||||||
|
self.visible.metacodes = self.filters.metacodes.slice()
|
||||||
|
self.passFilters()
|
||||||
|
},
|
||||||
|
filterAllMappers: function (e) {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
$('#filter_by_mapper ul li').addClass('toggledOff')
|
||||||
|
$('.showAllMappers').removeClass('active')
|
||||||
|
$('.hideAllMappers').addClass('active')
|
||||||
|
self.visible.mappers = []
|
||||||
|
self.passFilters()
|
||||||
|
},
|
||||||
|
filterNoMappers: function (e) {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
$('#filter_by_mapper ul li').removeClass('toggledOff')
|
||||||
|
$('.showAllMappers').addClass('active')
|
||||||
|
$('.hideAllMappers').removeClass('active')
|
||||||
|
self.visible.mappers = self.filters.mappers.slice()
|
||||||
|
self.passFilters()
|
||||||
|
},
|
||||||
|
filterAllSynapses: function (e) {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
$('#filter_by_synapse ul li').addClass('toggledOff')
|
||||||
|
$('.showAllSynapses').removeClass('active')
|
||||||
|
$('.hideAllSynapses').addClass('active')
|
||||||
|
self.visible.synapses = []
|
||||||
|
self.passFilters()
|
||||||
|
},
|
||||||
|
filterNoSynapses: function (e) {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
$('#filter_by_synapse ul li').removeClass('toggledOff')
|
||||||
|
$('.showAllSynapses').addClass('active')
|
||||||
|
$('.hideAllSynapses').removeClass('active')
|
||||||
|
self.visible.synapses = self.filters.synapses.slice()
|
||||||
|
self.passFilters()
|
||||||
|
},
|
||||||
|
// an abstraction function for toggleMetacode, toggleMapper, toggleSynapse
|
||||||
|
// to reduce code redundancy
|
||||||
|
// gets called in the context of a list item in a filter box
|
||||||
|
toggleLi: function (whichToFilter) {
|
||||||
|
var self = Metamaps.Filter, index
|
||||||
|
var id = $(this).attr('data-id')
|
||||||
|
if (self.visible[whichToFilter].indexOf(id) == -1) {
|
||||||
|
self.visible[whichToFilter].push(id)
|
||||||
|
$(this).removeClass('toggledOff')
|
||||||
|
} else {
|
||||||
|
index = self.visible[whichToFilter].indexOf(id)
|
||||||
|
self.visible[whichToFilter].splice(index, 1)
|
||||||
|
$(this).addClass('toggledOff')
|
||||||
|
}
|
||||||
|
self.passFilters()
|
||||||
|
},
|
||||||
|
toggleMetacode: function () {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
self.toggleLi.call(this, 'metacodes')
|
||||||
|
|
||||||
|
if (self.visible.metacodes.length === self.filters.metacodes.length) {
|
||||||
|
$('.showAllMetacodes').addClass('active')
|
||||||
|
$('.hideAllMetacodes').removeClass('active')
|
||||||
|
}
|
||||||
|
else if (self.visible.metacodes.length === 0) {
|
||||||
|
$('.showAllMetacodes').removeClass('active')
|
||||||
|
$('.hideAllMetacodes').addClass('active')
|
||||||
|
} else {
|
||||||
|
$('.showAllMetacodes').removeClass('active')
|
||||||
|
$('.hideAllMetacodes').removeClass('active')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
toggleMapper: function () {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
self.toggleLi.call(this, 'mappers')
|
||||||
|
|
||||||
|
if (self.visible.mappers.length === self.filters.mappers.length) {
|
||||||
|
$('.showAllMappers').addClass('active')
|
||||||
|
$('.hideAllMappers').removeClass('active')
|
||||||
|
}
|
||||||
|
else if (self.visible.mappers.length === 0) {
|
||||||
|
$('.showAllMappers').removeClass('active')
|
||||||
|
$('.hideAllMappers').addClass('active')
|
||||||
|
} else {
|
||||||
|
$('.showAllMappers').removeClass('active')
|
||||||
|
$('.hideAllMappers').removeClass('active')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
toggleSynapse: function () {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
self.toggleLi.call(this, 'synapses')
|
||||||
|
|
||||||
|
if (self.visible.synapses.length === self.filters.synapses.length) {
|
||||||
|
$('.showAllSynapses').addClass('active')
|
||||||
|
$('.hideAllSynapses').removeClass('active')
|
||||||
|
}
|
||||||
|
else if (self.visible.synapses.length === 0) {
|
||||||
|
$('.showAllSynapses').removeClass('active')
|
||||||
|
$('.hideAllSynapses').addClass('active')
|
||||||
|
} else {
|
||||||
|
$('.showAllSynapses').removeClass('active')
|
||||||
|
$('.hideAllSynapses').removeClass('active')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
passFilters: function () {
|
||||||
|
var self = Metamaps.Filter
|
||||||
|
var visible = self.visible
|
||||||
|
|
||||||
|
var passesMetacode, passesMapper, passesSynapse
|
||||||
|
var onMap
|
||||||
|
|
||||||
|
if (Metamaps.Active.Map) {
|
||||||
|
onMap = true
|
||||||
|
}
|
||||||
|
else if (Metamaps.Active.Topic) {
|
||||||
|
onMap = false
|
||||||
|
}
|
||||||
|
|
||||||
|
var opacityForFilter = onMap ? 0 : 0.4
|
||||||
|
|
||||||
|
Metamaps.Topics.each(function (topic) {
|
||||||
|
var n = topic.get('node')
|
||||||
|
var metacode_id = topic.get('metacode_id').toString()
|
||||||
|
|
||||||
|
if (visible.metacodes.indexOf(metacode_id) == -1) passesMetacode = false
|
||||||
|
else passesMetacode = true
|
||||||
|
|
||||||
|
if (onMap) {
|
||||||
|
// when on a map,
|
||||||
|
// we filter by mapper according to the person who added the
|
||||||
|
// topic or synapse to the map
|
||||||
|
var user_id = topic.getMapping().get('user_id').toString()
|
||||||
|
if (visible.mappers.indexOf(user_id) == -1) passesMapper = false
|
||||||
|
else passesMapper = true
|
||||||
|
} else {
|
||||||
|
// when on a topic view,
|
||||||
|
// we filter by mapper according to the person who created the
|
||||||
|
// topic or synapse
|
||||||
|
var user_id = topic.get('user_id').toString()
|
||||||
|
if (visible.mappers.indexOf(user_id) == -1) passesMapper = false
|
||||||
|
else passesMapper = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (passesMetacode && passesMapper) {
|
||||||
|
if (n) {
|
||||||
|
n.setData('alpha', 1, 'end')
|
||||||
|
}
|
||||||
|
else console.log(topic)
|
||||||
|
} else {
|
||||||
|
if (n) {
|
||||||
|
Metamaps.Control.deselectNode(n, true)
|
||||||
|
n.setData('alpha', opacityForFilter, 'end')
|
||||||
|
n.eachAdjacency(function (e) {
|
||||||
|
Metamaps.Control.deselectEdge(e, true)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else console.log(topic)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// flag all the edges back to 'untouched'
|
||||||
|
Metamaps.Synapses.each(function (synapse) {
|
||||||
|
var e = synapse.get('edge')
|
||||||
|
e.setData('touched', false)
|
||||||
|
})
|
||||||
|
Metamaps.Synapses.each(function (synapse) {
|
||||||
|
var e = synapse.get('edge')
|
||||||
|
var desc
|
||||||
|
var user_id = synapse.get('user_id').toString()
|
||||||
|
|
||||||
|
if (e && !e.getData('touched')) {
|
||||||
|
var synapses = e.getData('synapses')
|
||||||
|
|
||||||
|
// if any of the synapses represent by the edge are still unfiltered
|
||||||
|
// leave the edge visible
|
||||||
|
passesSynapse = false
|
||||||
|
for (var i = 0; i < synapses.length; i++) {
|
||||||
|
desc = synapses[i].get('desc')
|
||||||
|
if (visible.synapses.indexOf(desc) > -1) passesSynapse = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the synapse description being displayed is now being
|
||||||
|
// filtered, set the displayIndex to the first unfiltered synapse if there is one
|
||||||
|
var displayIndex = e.getData('displayIndex') ? e.getData('displayIndex') : 0
|
||||||
|
var displayedSynapse = synapses[displayIndex]
|
||||||
|
desc = displayedSynapse.get('desc')
|
||||||
|
if (passesSynapse && visible.synapses.indexOf(desc) == -1) {
|
||||||
|
// iterate and find an unfiltered one
|
||||||
|
for (var i = 0; i < synapses.length; i++) {
|
||||||
|
desc = synapses[i].get('desc')
|
||||||
|
if (visible.synapses.indexOf(desc) > -1) {
|
||||||
|
e.setData('displayIndex', i)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onMap) {
|
||||||
|
// when on a map,
|
||||||
|
// we filter by mapper according to the person who added the
|
||||||
|
// topic or synapse to the map
|
||||||
|
user_id = synapse.getMapping().get('user_id').toString()
|
||||||
|
}
|
||||||
|
if (visible.mappers.indexOf(user_id) == -1) passesMapper = false
|
||||||
|
else passesMapper = true
|
||||||
|
|
||||||
|
var color = Metamaps.Settings.colors.synapses.normal
|
||||||
|
if (passesSynapse && passesMapper) {
|
||||||
|
e.setData('alpha', 1, 'end')
|
||||||
|
e.setData('color', color, 'end')
|
||||||
|
} else {
|
||||||
|
Metamaps.Control.deselectEdge(e, true)
|
||||||
|
e.setData('alpha', opacityForFilter, 'end')
|
||||||
|
}
|
||||||
|
|
||||||
|
e.setData('touched', true)
|
||||||
|
}
|
||||||
|
else if (!e) console.log(synapse)
|
||||||
|
})
|
||||||
|
|
||||||
|
// run the animation
|
||||||
|
Metamaps.Visualize.mGraph.fx.animate({
|
||||||
|
modes: ['node-property:alpha',
|
||||||
|
'edge-property:alpha'],
|
||||||
|
duration: 200
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}; // end Metamaps.Filter
|
|
@ -93,6 +93,7 @@ Metamaps.GlobalUI = {
|
||||||
if (Metamaps.Active.Mapper) Metamaps.Active.Mapper = new Metamaps.Backbone.Mapper(Metamaps.Active.Mapper);
|
if (Metamaps.Active.Mapper) Metamaps.Active.Mapper = new Metamaps.Backbone.Mapper(Metamaps.Active.Mapper);
|
||||||
|
|
||||||
var myCollection = Metamaps.Maps.Mine ? Metamaps.Maps.Mine : [];
|
var myCollection = Metamaps.Maps.Mine ? Metamaps.Maps.Mine : [];
|
||||||
|
var sharedCollection = Metamaps.Maps.Shared ? Metamaps.Maps.Shared : [];
|
||||||
var mapperCollection = [];
|
var mapperCollection = [];
|
||||||
var mapperOptionsObj = {id: 'mapper', sortBy: 'updated_at' };
|
var mapperOptionsObj = {id: 'mapper', sortBy: 'updated_at' };
|
||||||
if (Metamaps.Maps.Mapper) {
|
if (Metamaps.Maps.Mapper) {
|
||||||
|
@ -102,6 +103,7 @@ Metamaps.GlobalUI = {
|
||||||
var featuredCollection = Metamaps.Maps.Featured ? Metamaps.Maps.Featured : [];
|
var featuredCollection = Metamaps.Maps.Featured ? Metamaps.Maps.Featured : [];
|
||||||
var activeCollection = Metamaps.Maps.Active ? Metamaps.Maps.Active : [];
|
var activeCollection = Metamaps.Maps.Active ? Metamaps.Maps.Active : [];
|
||||||
Metamaps.Maps.Mine = new Metamaps.Backbone.MapsCollection(myCollection, {id: 'mine', sortBy: 'updated_at' });
|
Metamaps.Maps.Mine = new Metamaps.Backbone.MapsCollection(myCollection, {id: 'mine', sortBy: 'updated_at' });
|
||||||
|
Metamaps.Maps.Shared = new Metamaps.Backbone.MapsCollection(sharedCollection, {id: 'shared', sortBy: 'updated_at' });
|
||||||
// 'Mapper' refers to another mapper
|
// 'Mapper' refers to another mapper
|
||||||
Metamaps.Maps.Mapper = new Metamaps.Backbone.MapsCollection(mapperCollection, mapperOptionsObj);
|
Metamaps.Maps.Mapper = new Metamaps.Backbone.MapsCollection(mapperCollection, mapperOptionsObj);
|
||||||
Metamaps.Maps.Featured = new Metamaps.Backbone.MapsCollection(featuredCollection, {id: 'featured', sortBy: 'updated_at' });
|
Metamaps.Maps.Featured = new Metamaps.Backbone.MapsCollection(featuredCollection, {id: 'featured', sortBy: 'updated_at' });
|
||||||
|
@ -501,7 +503,7 @@ Metamaps.GlobalUI.Search = {
|
||||||
return Hogan.compile(topicheader + $('#topicSearchTemplate').html()).render({
|
return Hogan.compile(topicheader + $('#topicSearchTemplate').html()).render({
|
||||||
value: "No results",
|
value: "No results",
|
||||||
label: "No results",
|
label: "No results",
|
||||||
typeImageURL: "<%= asset_path('icons/wildcard.png') %>",
|
typeImageURL: Metamaps.Erb['icons/wildcard.png'],
|
||||||
rtype: "noresult"
|
rtype: "noresult"
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -569,7 +571,7 @@ Metamaps.GlobalUI.Search = {
|
||||||
value: "No results",
|
value: "No results",
|
||||||
label: "No results",
|
label: "No results",
|
||||||
rtype: "noresult",
|
rtype: "noresult",
|
||||||
profile: "<%= asset_path('user.png') %>",
|
profile: Metamaps.Erb['user.png']
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
header: mapperheader,
|
header: mapperheader,
|
|
@ -320,3 +320,5 @@ Metamaps.Import = {
|
||||||
Metamaps.Synapse.renderSynapse(mapping, synapse, node1, node2, true)
|
Metamaps.Synapse.renderSynapse(mapping, synapse, node1, node2, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = Metamaps.Import
|
1908
app/assets/javascripts/src/Metamaps.JIT.js
Normal file
1908
app/assets/javascripts/src/Metamaps.JIT.js
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
78
app/assets/javascripts/src/Metamaps.Listeners.js
Normal file
78
app/assets/javascripts/src/Metamaps.Listeners.js
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
/* global Metamaps, $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Metamaps.Listeners.js.erb
|
||||||
|
*
|
||||||
|
* Dependencies:
|
||||||
|
* - Metamaps.Active
|
||||||
|
* - Metamaps.Control
|
||||||
|
* - Metamaps.JIT
|
||||||
|
* - Metamaps.Visualize
|
||||||
|
*/
|
||||||
|
Metamaps.Listeners = {
|
||||||
|
init: function () {
|
||||||
|
$(document).on('keydown', function (e) {
|
||||||
|
if (!(Metamaps.Active.Map || Metamaps.Active.Topic)) return
|
||||||
|
|
||||||
|
switch (e.which) {
|
||||||
|
case 13: // if enter key is pressed
|
||||||
|
Metamaps.JIT.enterKeyHandler()
|
||||||
|
e.preventDefault()
|
||||||
|
break
|
||||||
|
case 27: // if esc key is pressed
|
||||||
|
Metamaps.JIT.escKeyHandler()
|
||||||
|
break
|
||||||
|
case 65: // if a or A is pressed
|
||||||
|
if (e.ctrlKey) {
|
||||||
|
Metamaps.Control.deselectAllNodes()
|
||||||
|
Metamaps.Control.deselectAllEdges()
|
||||||
|
|
||||||
|
e.preventDefault()
|
||||||
|
Metamaps.Visualize.mGraph.graph.eachNode(function (n) {
|
||||||
|
Metamaps.Control.selectNode(n, e)
|
||||||
|
})
|
||||||
|
|
||||||
|
Metamaps.Visualize.mGraph.plot()
|
||||||
|
}
|
||||||
|
|
||||||
|
break
|
||||||
|
case 69: // if e or E is pressed
|
||||||
|
if (e.ctrlKey) {
|
||||||
|
e.preventDefault()
|
||||||
|
if (Metamaps.Active.Map) {
|
||||||
|
Metamaps.JIT.zoomExtents(null, Metamaps.Visualize.mGraph.canvas)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 77: // if m or M is pressed
|
||||||
|
if (e.ctrlKey) {
|
||||||
|
e.preventDefault()
|
||||||
|
Metamaps.Control.removeSelectedNodes()
|
||||||
|
Metamaps.Control.removeSelectedEdges()
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 68: // if d or D is pressed
|
||||||
|
if (e.ctrlKey) {
|
||||||
|
e.preventDefault()
|
||||||
|
Metamaps.Control.deleteSelected()
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 72: // if h or H is pressed
|
||||||
|
if (e.ctrlKey) {
|
||||||
|
e.preventDefault()
|
||||||
|
Metamaps.Control.hideSelectedNodes()
|
||||||
|
Metamaps.Control.hideSelectedEdges()
|
||||||
|
}
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
break; // alert(e.which)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
$(window).resize(function () {
|
||||||
|
if (Metamaps.Visualize && Metamaps.Visualize.mGraph) Metamaps.Visualize.mGraph.canvas.resize($(window).width(), $(window).height())
|
||||||
|
if ((Metamaps.Active.Map || Metamaps.Active.Topic) && Metamaps.Famous && Metamaps.Famous.maps.surf) Metamaps.Famous.maps.reposition()
|
||||||
|
if (Metamaps.Active.Map && Metamaps.Realtime.inConversation) Metamaps.Realtime.positionVideos()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}; // end Metamaps.Listeners
|
763
app/assets/javascripts/src/Metamaps.Map.js
Normal file
763
app/assets/javascripts/src/Metamaps.Map.js
Normal file
|
@ -0,0 +1,763 @@
|
||||||
|
/* global Metamaps, $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Metamaps.Map.js.erb
|
||||||
|
*
|
||||||
|
* Dependencies:
|
||||||
|
* - Metamaps.Create
|
||||||
|
* - Metamaps.Erb
|
||||||
|
* - Metamaps.Filter
|
||||||
|
* - Metamaps.JIT
|
||||||
|
* - Metamaps.Loading
|
||||||
|
* - Metamaps.Maps
|
||||||
|
* - Metamaps.Realtime
|
||||||
|
* - Metamaps.Router
|
||||||
|
* - Metamaps.Selected
|
||||||
|
* - Metamaps.SynapseCard
|
||||||
|
* - Metamaps.TopicCard
|
||||||
|
* - Metamaps.Visualize
|
||||||
|
* - Metamaps.Active
|
||||||
|
* - Metamaps.Backbone
|
||||||
|
* - Metamaps.GlobalUI
|
||||||
|
* - Metamaps.Mappers
|
||||||
|
* - Metamaps.Mappings
|
||||||
|
* - Metamaps.Messages
|
||||||
|
* - Metamaps.Synapses
|
||||||
|
* - Metamaps.Topics
|
||||||
|
*
|
||||||
|
* Major sub-modules:
|
||||||
|
* - Metamaps.Map.CheatSheet
|
||||||
|
* - Metamaps.Map.InfoBox
|
||||||
|
*/
|
||||||
|
|
||||||
|
Metamaps.Map = {
|
||||||
|
events: {
|
||||||
|
editedByActiveMapper: 'Metamaps:Map:events:editedByActiveMapper'
|
||||||
|
},
|
||||||
|
nextX: 0,
|
||||||
|
nextY: 0,
|
||||||
|
sideLength: 1,
|
||||||
|
turnCount: 0,
|
||||||
|
nextXshift: 1,
|
||||||
|
nextYshift: 0,
|
||||||
|
timeToTurn: 0,
|
||||||
|
init: function () {
|
||||||
|
var self = Metamaps.Map
|
||||||
|
|
||||||
|
// prevent right clicks on the main canvas, so as to not get in the way of our right clicks
|
||||||
|
$('#center-container').bind('contextmenu', function (e) {
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
|
$('.sidebarFork').click(function () {
|
||||||
|
self.fork()
|
||||||
|
})
|
||||||
|
|
||||||
|
Metamaps.GlobalUI.CreateMap.emptyForkMapForm = $('#fork_map').html()
|
||||||
|
|
||||||
|
self.InfoBox.init()
|
||||||
|
self.CheatSheet.init()
|
||||||
|
|
||||||
|
$(document).on(Metamaps.Map.events.editedByActiveMapper, self.editedByActiveMapper)
|
||||||
|
},
|
||||||
|
launch: function (id) {
|
||||||
|
var bb = Metamaps.Backbone
|
||||||
|
var start = function (data) {
|
||||||
|
Metamaps.Active.Map = new bb.Map(data.map)
|
||||||
|
Metamaps.Mappers = new bb.MapperCollection(data.mappers)
|
||||||
|
Metamaps.Collaborators = new bb.MapperCollection(data.collaborators)
|
||||||
|
Metamaps.Topics = new bb.TopicCollection(data.topics)
|
||||||
|
Metamaps.Synapses = new bb.SynapseCollection(data.synapses)
|
||||||
|
Metamaps.Mappings = new bb.MappingCollection(data.mappings)
|
||||||
|
Metamaps.Messages = data.messages
|
||||||
|
Metamaps.Backbone.attachCollectionEvents()
|
||||||
|
|
||||||
|
var map = Metamaps.Active.Map
|
||||||
|
var mapper = Metamaps.Active.Mapper
|
||||||
|
|
||||||
|
// add class to .wrapper for specifying whether you can edit the map
|
||||||
|
if (map.authorizeToEdit(mapper)) {
|
||||||
|
$('.wrapper').addClass('canEditMap')
|
||||||
|
}
|
||||||
|
|
||||||
|
// add class to .wrapper for specifying if the map can
|
||||||
|
// be collaborated on
|
||||||
|
if (map.get('permission') === 'commons') {
|
||||||
|
$('.wrapper').addClass('commonsMap')
|
||||||
|
}
|
||||||
|
|
||||||
|
// set filter mapper H3 text
|
||||||
|
$('#filter_by_mapper h3').html('MAPPERS')
|
||||||
|
|
||||||
|
// build and render the visualization
|
||||||
|
Metamaps.Visualize.type = 'ForceDirected'
|
||||||
|
Metamaps.JIT.prepareVizData()
|
||||||
|
|
||||||
|
// update filters
|
||||||
|
Metamaps.Filter.reset()
|
||||||
|
|
||||||
|
// reset selected arrays
|
||||||
|
Metamaps.Selected.reset()
|
||||||
|
|
||||||
|
// set the proper mapinfobox content
|
||||||
|
Metamaps.Map.InfoBox.load()
|
||||||
|
|
||||||
|
// these three update the actual filter box with the right list items
|
||||||
|
Metamaps.Filter.checkMetacodes()
|
||||||
|
Metamaps.Filter.checkSynapses()
|
||||||
|
Metamaps.Filter.checkMappers()
|
||||||
|
|
||||||
|
Metamaps.Realtime.startActiveMap()
|
||||||
|
Metamaps.Loading.hide()
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/maps/' + id + '/contains.json',
|
||||||
|
success: start
|
||||||
|
})
|
||||||
|
},
|
||||||
|
end: function () {
|
||||||
|
if (Metamaps.Active.Map) {
|
||||||
|
$('.wrapper').removeClass('canEditMap commonsMap')
|
||||||
|
Metamaps.Map.resetSpiral()
|
||||||
|
|
||||||
|
$('.rightclickmenu').remove()
|
||||||
|
Metamaps.TopicCard.hideCard()
|
||||||
|
Metamaps.SynapseCard.hideCard()
|
||||||
|
Metamaps.Create.newTopic.hide()
|
||||||
|
Metamaps.Create.newSynapse.hide()
|
||||||
|
Metamaps.Filter.close()
|
||||||
|
Metamaps.Map.InfoBox.close()
|
||||||
|
Metamaps.Realtime.endActiveMap()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fork: function () {
|
||||||
|
Metamaps.GlobalUI.openLightbox('forkmap')
|
||||||
|
|
||||||
|
var nodes_data = '',
|
||||||
|
synapses_data = ''
|
||||||
|
var nodes_array = []
|
||||||
|
var synapses_array = []
|
||||||
|
// collect the unfiltered topics
|
||||||
|
Metamaps.Visualize.mGraph.graph.eachNode(function (n) {
|
||||||
|
// if the opacity is less than 1 then it's filtered
|
||||||
|
if (n.getData('alpha') === 1) {
|
||||||
|
var id = n.getData('topic').id
|
||||||
|
nodes_array.push(id)
|
||||||
|
var x, y
|
||||||
|
if (n.pos.x && n.pos.y) {
|
||||||
|
x = n.pos.x
|
||||||
|
y = n.pos.y
|
||||||
|
} else {
|
||||||
|
var x = Math.cos(n.pos.theta) * n.pos.rho
|
||||||
|
var y = Math.sin(n.pos.theta) * n.pos.rho
|
||||||
|
}
|
||||||
|
nodes_data += id + '/' + x + '/' + y + ','
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// collect the unfiltered synapses
|
||||||
|
Metamaps.Synapses.each(function (synapse) {
|
||||||
|
var desc = synapse.get('desc')
|
||||||
|
|
||||||
|
var descNotFiltered = Metamaps.Filter.visible.synapses.indexOf(desc) > -1
|
||||||
|
// make sure that both topics are being added, otherwise, it
|
||||||
|
// doesn't make sense to add the synapse
|
||||||
|
var topicsNotFiltered = nodes_array.indexOf(synapse.get('node1_id')) > -1
|
||||||
|
topicsNotFiltered = topicsNotFiltered && nodes_array.indexOf(synapse.get('node2_id')) > -1
|
||||||
|
if (descNotFiltered && topicsNotFiltered) {
|
||||||
|
synapses_array.push(synapse.id)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
synapses_data = synapses_array.join()
|
||||||
|
nodes_data = nodes_data.slice(0, -1)
|
||||||
|
|
||||||
|
Metamaps.GlobalUI.CreateMap.topicsToMap = nodes_data
|
||||||
|
Metamaps.GlobalUI.CreateMap.synapsesToMap = synapses_data
|
||||||
|
},
|
||||||
|
leavePrivateMap: function () {
|
||||||
|
var map = Metamaps.Active.Map
|
||||||
|
Metamaps.Maps.Active.remove(map)
|
||||||
|
Metamaps.Maps.Featured.remove(map)
|
||||||
|
Metamaps.Router.home()
|
||||||
|
Metamaps.GlobalUI.notifyUser('Sorry! That map has been changed to Private.')
|
||||||
|
},
|
||||||
|
cantEditNow: function () {
|
||||||
|
Metamaps.Realtime.turnOff(true); // true is for 'silence'
|
||||||
|
Metamaps.GlobalUI.notifyUser('Map was changed to Public. Editing is disabled.')
|
||||||
|
Metamaps.Active.Map.trigger('changeByOther')
|
||||||
|
},
|
||||||
|
canEditNow: function () {
|
||||||
|
var confirmString = "You've been granted permission to edit this map. "
|
||||||
|
confirmString += 'Do you want to reload and enable realtime collaboration?'
|
||||||
|
var c = confirm(confirmString)
|
||||||
|
if (c) {
|
||||||
|
Metamaps.Router.maps(Metamaps.Active.Map.id)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
editedByActiveMapper: function () {
|
||||||
|
if (Metamaps.Active.Mapper) {
|
||||||
|
Metamaps.Mappers.add(Metamaps.Active.Mapper)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getNextCoord: function () {
|
||||||
|
var self = Metamaps.Map
|
||||||
|
var nextX = self.nextX
|
||||||
|
var nextY = self.nextY
|
||||||
|
|
||||||
|
var DISTANCE_BETWEEN = 120
|
||||||
|
|
||||||
|
self.nextX = self.nextX + DISTANCE_BETWEEN * self.nextXshift
|
||||||
|
self.nextY = self.nextY + DISTANCE_BETWEEN * self.nextYshift
|
||||||
|
|
||||||
|
self.timeToTurn += 1
|
||||||
|
// if true, it's time to turn
|
||||||
|
if (self.timeToTurn === self.sideLength) {
|
||||||
|
self.turnCount += 1
|
||||||
|
// if true, it's time to increase side length
|
||||||
|
if (self.turnCount % 2 === 0) {
|
||||||
|
self.sideLength += 1
|
||||||
|
}
|
||||||
|
self.timeToTurn = 0
|
||||||
|
|
||||||
|
// going right? turn down
|
||||||
|
if (self.nextXshift == 1 && self.nextYshift == 0) {
|
||||||
|
self.nextXshift = 0
|
||||||
|
self.nextYshift = 1
|
||||||
|
}
|
||||||
|
// going down? turn left
|
||||||
|
else if (self.nextXshift == 0 && self.nextYshift == 1) {
|
||||||
|
self.nextXshift = -1
|
||||||
|
self.nextYshift = 0
|
||||||
|
}
|
||||||
|
// going left? turn up
|
||||||
|
else if (self.nextXshift == -1 && self.nextYshift == 0) {
|
||||||
|
self.nextXshift = 0
|
||||||
|
self.nextYshift = -1
|
||||||
|
}
|
||||||
|
// going up? turn right
|
||||||
|
else if (self.nextXshift == 0 && self.nextYshift == -1) {
|
||||||
|
self.nextXshift = 1
|
||||||
|
self.nextYshift = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
x: nextX,
|
||||||
|
y: nextY
|
||||||
|
}
|
||||||
|
},
|
||||||
|
resetSpiral: function () {
|
||||||
|
Metamaps.Map.nextX = 0
|
||||||
|
Metamaps.Map.nextY = 0
|
||||||
|
Metamaps.Map.nextXshift = 1
|
||||||
|
Metamaps.Map.nextYshift = 0
|
||||||
|
Metamaps.Map.sideLength = 1
|
||||||
|
Metamaps.Map.timeToTurn = 0
|
||||||
|
Metamaps.Map.turnCount = 0
|
||||||
|
},
|
||||||
|
exportImage: function () {
|
||||||
|
var canvas = {}
|
||||||
|
|
||||||
|
canvas.canvas = document.createElement('canvas')
|
||||||
|
canvas.canvas.width = 1880 // 960
|
||||||
|
canvas.canvas.height = 1260 // 630
|
||||||
|
|
||||||
|
canvas.scaleOffsetX = 1
|
||||||
|
canvas.scaleOffsetY = 1
|
||||||
|
canvas.translateOffsetY = 0
|
||||||
|
canvas.translateOffsetX = 0
|
||||||
|
canvas.denySelected = true
|
||||||
|
|
||||||
|
canvas.getSize = function () {
|
||||||
|
if (this.size) return this.size
|
||||||
|
var canvas = this.canvas
|
||||||
|
return this.size = {
|
||||||
|
width: canvas.width,
|
||||||
|
height: canvas.height
|
||||||
|
}
|
||||||
|
}
|
||||||
|
canvas.scale = function (x, y) {
|
||||||
|
var px = this.scaleOffsetX * x,
|
||||||
|
py = this.scaleOffsetY * y
|
||||||
|
var dx = this.translateOffsetX * (x - 1) / px,
|
||||||
|
dy = this.translateOffsetY * (y - 1) / py
|
||||||
|
this.scaleOffsetX = px
|
||||||
|
this.scaleOffsetY = py
|
||||||
|
this.getCtx().scale(x, y)
|
||||||
|
this.translate(dx, dy)
|
||||||
|
}
|
||||||
|
canvas.translate = function (x, y) {
|
||||||
|
var sx = this.scaleOffsetX,
|
||||||
|
sy = this.scaleOffsetY
|
||||||
|
this.translateOffsetX += x * sx
|
||||||
|
this.translateOffsetY += y * sy
|
||||||
|
this.getCtx().translate(x, y)
|
||||||
|
}
|
||||||
|
canvas.getCtx = function () {
|
||||||
|
return this.canvas.getContext('2d')
|
||||||
|
}
|
||||||
|
// center it
|
||||||
|
canvas.getCtx().translate(1880 / 2, 1260 / 2)
|
||||||
|
|
||||||
|
var mGraph = Metamaps.Visualize.mGraph
|
||||||
|
|
||||||
|
var id = mGraph.root
|
||||||
|
var root = mGraph.graph.getNode(id)
|
||||||
|
var T = !!root.visited
|
||||||
|
|
||||||
|
// pass true to avoid basing it on a selection
|
||||||
|
Metamaps.JIT.zoomExtents(null, canvas, true)
|
||||||
|
|
||||||
|
var c = canvas.canvas,
|
||||||
|
ctx = canvas.getCtx(),
|
||||||
|
scale = canvas.scaleOffsetX
|
||||||
|
|
||||||
|
// draw a grey background
|
||||||
|
ctx.fillStyle = '#d8d9da'
|
||||||
|
var xPoint = (-(c.width / scale) / 2) - (canvas.translateOffsetX / scale),
|
||||||
|
yPoint = (-(c.height / scale) / 2) - (canvas.translateOffsetY / scale)
|
||||||
|
ctx.fillRect(xPoint, yPoint, c.width / scale, c.height / scale)
|
||||||
|
|
||||||
|
// draw the graph
|
||||||
|
mGraph.graph.eachNode(function (node) {
|
||||||
|
var nodeAlpha = node.getData('alpha')
|
||||||
|
node.eachAdjacency(function (adj) {
|
||||||
|
var nodeTo = adj.nodeTo
|
||||||
|
if (!!nodeTo.visited === T && node.drawn && nodeTo.drawn) {
|
||||||
|
mGraph.fx.plotLine(adj, canvas)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (node.drawn) {
|
||||||
|
mGraph.fx.plotNode(node, canvas)
|
||||||
|
}
|
||||||
|
if (!mGraph.labelsHidden) {
|
||||||
|
if (node.drawn && nodeAlpha >= 0.95) {
|
||||||
|
mGraph.labels.plotLabel(canvas, node)
|
||||||
|
} else {
|
||||||
|
mGraph.labels.hideLabel(node, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
node.visited = !T
|
||||||
|
})
|
||||||
|
|
||||||
|
var imageData = {
|
||||||
|
encoded_image: canvas.canvas.toDataURL()
|
||||||
|
}
|
||||||
|
|
||||||
|
var map = Metamaps.Active.Map
|
||||||
|
|
||||||
|
var today = new Date()
|
||||||
|
var dd = today.getDate()
|
||||||
|
var mm = today.getMonth() + 1; // January is 0!
|
||||||
|
var yyyy = today.getFullYear()
|
||||||
|
if (dd < 10) {
|
||||||
|
dd = '0' + dd
|
||||||
|
}
|
||||||
|
if (mm < 10) {
|
||||||
|
mm = '0' + mm
|
||||||
|
}
|
||||||
|
today = mm + '/' + dd + '/' + yyyy
|
||||||
|
|
||||||
|
var mapName = map.get('name').split(' ').join([separator = '-'])
|
||||||
|
var downloadMessage = ''
|
||||||
|
downloadMessage += 'Captured map screenshot! '
|
||||||
|
downloadMessage += "<a href='" + imageData.encoded_image + "' "
|
||||||
|
downloadMessage += "download='metamap-" + map.id + '-' + mapName + '-' + today + ".png'>DOWNLOAD</a>"
|
||||||
|
Metamaps.GlobalUI.notifyUser(downloadMessage)
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
url: '/maps/' + Metamaps.Active.Map.id + '/upload_screenshot',
|
||||||
|
data: imageData,
|
||||||
|
success: function (data) {
|
||||||
|
console.log('successfully uploaded map screenshot')
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
console.log('failed to save map screenshot')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* CHEATSHEET
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Metamaps.Map.CheatSheet = {
|
||||||
|
init: function () {
|
||||||
|
// tab the cheatsheet
|
||||||
|
$('#cheatSheet').tabs()
|
||||||
|
$('#quickReference').tabs().addClass('ui-tabs-vertical ui-helper-clearfix')
|
||||||
|
$('#quickReference .ui-tabs-nav li').removeClass('ui-corner-top').addClass('ui-corner-left')
|
||||||
|
|
||||||
|
// id = the id of a vimeo video
|
||||||
|
var switchVideo = function (element, id) {
|
||||||
|
$('.tutorialItem').removeClass('active')
|
||||||
|
$(element).addClass('active')
|
||||||
|
$('#tutorialVideo').attr('src', '//player.vimeo.com/video/' + id)
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#gettingStarted').click(function () {
|
||||||
|
// switchVideo(this,'88334167')
|
||||||
|
})
|
||||||
|
$('#upYourSkillz').click(function () {
|
||||||
|
// switchVideo(this,'100118167')
|
||||||
|
})
|
||||||
|
$('#advancedMapping').click(function () {
|
||||||
|
// switchVideo(this,'88334167')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}; // end Metamaps.Map.CheatSheet
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* INFOBOX
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Metamaps.Map.InfoBox = {
|
||||||
|
isOpen: false,
|
||||||
|
changing: false,
|
||||||
|
selectingPermission: false,
|
||||||
|
changePermissionText: "<div class='tooltips'>As the creator, you can change the permission of this map, and the permission of all the topics and synapses you have authority to change will change as well.</div>",
|
||||||
|
nameHTML: '<span class="best_in_place best_in_place_name" id="best_in_place_map_{{id}}_name" data-url="/maps/{{id}}" data-object="map" data-attribute="name" data-type="textarea" data-activator="#mapInfoName">{{name}}</span>',
|
||||||
|
descHTML: '<span class="best_in_place best_in_place_desc" id="best_in_place_map_{{id}}_desc" data-url="/maps/{{id}}" data-object="map" data-attribute="desc" data-nil="Click to add description..." data-type="textarea" data-activator="#mapInfoDesc">{{desc}}</span>',
|
||||||
|
init: function () {
|
||||||
|
var self = Metamaps.Map.InfoBox
|
||||||
|
|
||||||
|
$('.mapInfoIcon').click(self.toggleBox)
|
||||||
|
$('.mapInfoBox').click(function (event) {
|
||||||
|
event.stopPropagation()
|
||||||
|
})
|
||||||
|
$('body').click(self.close)
|
||||||
|
|
||||||
|
self.attachEventListeners()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
self.generateBoxHTML = Hogan.compile($('#mapInfoBoxTemplate').html())
|
||||||
|
},
|
||||||
|
toggleBox: function (event) {
|
||||||
|
var self = Metamaps.Map.InfoBox
|
||||||
|
|
||||||
|
if (self.isOpen) self.close()
|
||||||
|
else self.open()
|
||||||
|
|
||||||
|
event.stopPropagation()
|
||||||
|
},
|
||||||
|
open: function () {
|
||||||
|
var self = Metamaps.Map.InfoBox
|
||||||
|
$('.mapInfoIcon div').addClass('hide')
|
||||||
|
if (!self.isOpen && !self.changing) {
|
||||||
|
self.changing = true
|
||||||
|
$('.mapInfoBox').fadeIn(200, function () {
|
||||||
|
self.changing = false
|
||||||
|
self.isOpen = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
close: function () {
|
||||||
|
var self = Metamaps.Map.InfoBox
|
||||||
|
|
||||||
|
$('.mapInfoIcon div').removeClass('hide')
|
||||||
|
if (!self.changing) {
|
||||||
|
self.changing = true
|
||||||
|
$('.mapInfoBox').fadeOut(200, function () {
|
||||||
|
self.changing = false
|
||||||
|
self.isOpen = false
|
||||||
|
self.hidePermissionSelect()
|
||||||
|
$('.mapContributors .tip').hide()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
load: function () {
|
||||||
|
var self = Metamaps.Map.InfoBox
|
||||||
|
|
||||||
|
var map = Metamaps.Active.Map
|
||||||
|
|
||||||
|
var obj = map.pick('permission', 'topic_count', 'synapse_count')
|
||||||
|
|
||||||
|
var isCreator = map.authorizePermissionChange(Metamaps.Active.Mapper)
|
||||||
|
var canEdit = map.authorizeToEdit(Metamaps.Active.Mapper)
|
||||||
|
var relevantPeople = map.get('permission') === 'commons' ? Metamaps.Mappers : Metamaps.Collaborators
|
||||||
|
var shareable = map.get('permission') !== 'private'
|
||||||
|
|
||||||
|
obj['name'] = canEdit ? Hogan.compile(self.nameHTML).render({id: map.id, name: map.get('name')}) : map.get('name')
|
||||||
|
obj['desc'] = canEdit ? Hogan.compile(self.descHTML).render({id: map.id, desc: map.get('desc')}) : map.get('desc')
|
||||||
|
obj['map_creator_tip'] = isCreator ? self.changePermissionText : ''
|
||||||
|
|
||||||
|
obj['contributor_count'] = relevantPeople.length
|
||||||
|
obj['contributors_class'] = relevantPeople.length > 1 ? 'multiple' : ''
|
||||||
|
obj['contributors_class'] += relevantPeople.length === 2 ? ' mTwo' : ''
|
||||||
|
obj['contributor_image'] = relevantPeople.length > 0 ? relevantPeople.models[0].get('image') : Metamaps.Erb['user.png']
|
||||||
|
obj['contributor_list'] = self.createContributorList()
|
||||||
|
|
||||||
|
obj['user_name'] = isCreator ? 'You' : map.get('user_name')
|
||||||
|
obj['created_at'] = map.get('created_at_clean')
|
||||||
|
obj['updated_at'] = map.get('updated_at_clean')
|
||||||
|
|
||||||
|
var classes = isCreator ? 'yourMap' : ''
|
||||||
|
classes += canEdit ? ' canEdit' : ''
|
||||||
|
classes += shareable ? ' shareable' : ''
|
||||||
|
$('.mapInfoBox').removeClass('shareable yourMap canEdit')
|
||||||
|
.addClass(classes)
|
||||||
|
.html(self.generateBoxHTML.render(obj))
|
||||||
|
|
||||||
|
self.attachEventListeners()
|
||||||
|
},
|
||||||
|
attachEventListeners: function () {
|
||||||
|
var self = Metamaps.Map.InfoBox
|
||||||
|
|
||||||
|
$('.mapInfoBox.canEdit .best_in_place').best_in_place()
|
||||||
|
|
||||||
|
// because anyone who can edit the map can change the map title
|
||||||
|
var bipName = $('.mapInfoBox .best_in_place_name')
|
||||||
|
bipName.unbind('best_in_place:activate').bind('best_in_place:activate', function () {
|
||||||
|
var $el = bipName.find('textarea')
|
||||||
|
var el = $el[0]
|
||||||
|
|
||||||
|
$el.attr('maxlength', '140')
|
||||||
|
|
||||||
|
$('.mapInfoName').append('<div class="nameCounter forMap"></div>')
|
||||||
|
|
||||||
|
var callback = function (data) {
|
||||||
|
$('.nameCounter.forMap').html(data.all + '/140')
|
||||||
|
}
|
||||||
|
Countable.live(el, callback)
|
||||||
|
})
|
||||||
|
bipName.unbind('best_in_place:deactivate').bind('best_in_place:deactivate', function () {
|
||||||
|
$('.nameCounter.forMap').remove()
|
||||||
|
})
|
||||||
|
|
||||||
|
$('.mapInfoName .best_in_place_name').unbind('ajax:success').bind('ajax:success', function () {
|
||||||
|
var name = $(this).html()
|
||||||
|
Metamaps.Active.Map.set('name', name)
|
||||||
|
Metamaps.Active.Map.trigger('saved')
|
||||||
|
})
|
||||||
|
|
||||||
|
$('.mapInfoDesc .best_in_place_desc').unbind('ajax:success').bind('ajax:success', function () {
|
||||||
|
var desc = $(this).html()
|
||||||
|
Metamaps.Active.Map.set('desc', desc)
|
||||||
|
Metamaps.Active.Map.trigger('saved')
|
||||||
|
})
|
||||||
|
|
||||||
|
$('.yourMap .mapPermission').unbind().click(self.onPermissionClick)
|
||||||
|
// .yourMap in the unbind/bind is just a namespace for the events
|
||||||
|
// not a reference to the class .yourMap on the .mapInfoBox
|
||||||
|
$('.mapInfoBox.yourMap').unbind('.yourMap').bind('click.yourMap', self.hidePermissionSelect)
|
||||||
|
|
||||||
|
$('.yourMap .mapInfoDelete').unbind().click(self.deleteActiveMap)
|
||||||
|
|
||||||
|
$('.mapContributors span, #mapContribs').unbind().click(function (event) {
|
||||||
|
$('.mapContributors .tip').toggle()
|
||||||
|
event.stopPropagation()
|
||||||
|
})
|
||||||
|
$('.mapContributors .tip').unbind().click(function (event) {
|
||||||
|
event.stopPropagation()
|
||||||
|
})
|
||||||
|
$('.mapContributors .tip li a').click(Metamaps.Router.intercept)
|
||||||
|
|
||||||
|
$('.mapInfoBox').unbind('.hideTip').bind('click.hideTip', function () {
|
||||||
|
$('.mapContributors .tip').hide()
|
||||||
|
})
|
||||||
|
|
||||||
|
self.addTypeahead()
|
||||||
|
},
|
||||||
|
addTypeahead: function () {
|
||||||
|
var self = Metamaps.Map.InfoBox
|
||||||
|
|
||||||
|
if (!Metamaps.Active.Map) return
|
||||||
|
|
||||||
|
// for autocomplete
|
||||||
|
var collaborators = {
|
||||||
|
name: 'collaborators',
|
||||||
|
limit: 9999,
|
||||||
|
display: function(s) { return s.label; },
|
||||||
|
templates: {
|
||||||
|
notFound: function(s) {
|
||||||
|
return Hogan.compile($('#collaboratorSearchTemplate').html()).render({
|
||||||
|
value: "No results",
|
||||||
|
label: "No results",
|
||||||
|
rtype: "noresult",
|
||||||
|
profile: Metamaps.Erb['user.png'],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
suggestion: function(s) {
|
||||||
|
return Hogan.compile($('#collaboratorSearchTemplate').html()).render(s);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
source: new Bloodhound({
|
||||||
|
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
|
||||||
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||||
|
remote: {
|
||||||
|
url: '/search/mappers?term=%QUERY',
|
||||||
|
wildcard: '%QUERY',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// for adding map collaborators, who will have edit rights
|
||||||
|
if (Metamaps.Active.Mapper && Metamaps.Active.Mapper.id === Metamaps.Active.Map.get('user_id')) {
|
||||||
|
$('.collaboratorSearchField').typeahead(
|
||||||
|
{
|
||||||
|
highlight: false,
|
||||||
|
},
|
||||||
|
[collaborators]
|
||||||
|
)
|
||||||
|
$('.collaboratorSearchField').bind('typeahead:select', self.handleResultClick)
|
||||||
|
$('.mapContributors .removeCollaborator').click(function () {
|
||||||
|
self.removeCollaborator(parseInt($(this).data('id')))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
removeCollaborator: function (collaboratorId) {
|
||||||
|
var self = Metamaps.Map.InfoBox
|
||||||
|
Metamaps.Collaborators.remove(Metamaps.Collaborators.get(collaboratorId))
|
||||||
|
var mapperIds = Metamaps.Collaborators.models.map(function (mapper) { return mapper.id })
|
||||||
|
$.post('/maps/' + Metamaps.Active.Map.id + '/access', { access: mapperIds })
|
||||||
|
self.updateNumbers()
|
||||||
|
},
|
||||||
|
addCollaborator: function (newCollaboratorId) {
|
||||||
|
var self = Metamaps.Map.InfoBox
|
||||||
|
|
||||||
|
if (Metamaps.Collaborators.get(newCollaboratorId)) {
|
||||||
|
Metamaps.GlobalUI.notifyUser('That user already has access')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
function callback(mapper) {
|
||||||
|
Metamaps.Collaborators.add(mapper)
|
||||||
|
var mapperIds = Metamaps.Collaborators.models.map(function (mapper) { return mapper.id })
|
||||||
|
$.post('/maps/' + Metamaps.Active.Map.id + '/access', { access: mapperIds })
|
||||||
|
var name = Metamaps.Collaborators.get(newCollaboratorId).get('name')
|
||||||
|
Metamaps.GlobalUI.notifyUser(name + ' will be notified by email')
|
||||||
|
self.updateNumbers()
|
||||||
|
}
|
||||||
|
|
||||||
|
$.getJSON('/users/' + newCollaboratorId + '.json', callback)
|
||||||
|
},
|
||||||
|
handleResultClick: function (event, item) {
|
||||||
|
var self = Metamaps.Map.InfoBox
|
||||||
|
|
||||||
|
self.addCollaborator(item.id)
|
||||||
|
$('.collaboratorSearchField').typeahead('val', '')
|
||||||
|
},
|
||||||
|
updateNameDescPerm: function (name, desc, perm) {
|
||||||
|
$('.mapInfoName .best_in_place_name').html(name)
|
||||||
|
$('.mapInfoDesc .best_in_place_desc').html(desc)
|
||||||
|
$('.mapInfoBox .mapPermission').removeClass('commons public private').addClass(perm)
|
||||||
|
},
|
||||||
|
createContributorList: function () {
|
||||||
|
var self = Metamaps.Map.InfoBox
|
||||||
|
var relevantPeople = Metamaps.Active.Map.get('permission') === 'commons' ? Metamaps.Mappers : Metamaps.Collaborators
|
||||||
|
var activeMapperIsCreator = Metamaps.Active.Mapper && Metamaps.Active.Mapper.id === Metamaps.Active.Map.get('user_id')
|
||||||
|
var string = ''
|
||||||
|
string += '<ul>'
|
||||||
|
|
||||||
|
relevantPeople.each(function (m) {
|
||||||
|
var isCreator = Metamaps.Active.Map.get('user_id') === m.get('id')
|
||||||
|
string += '<li><a href="/explore/mapper/' + m.get('id') + '">' + '<img class="rtUserImage" width="25" height="25" src="' + m.get('image') + '" />' + m.get('name')
|
||||||
|
if (isCreator) string += ' (creator)'
|
||||||
|
string += '</a>'
|
||||||
|
if (activeMapperIsCreator && !isCreator) string += '<span class="removeCollaborator" data-id="' + m.get('id') + '"></span>'
|
||||||
|
string += '</li>'
|
||||||
|
})
|
||||||
|
|
||||||
|
string += '</ul>'
|
||||||
|
|
||||||
|
if (activeMapperIsCreator) {
|
||||||
|
string += '<div class="collabSearchField"><span class="addCollab"></span><input class="collaboratorSearchField" placeholder="Add a collaborator!"></input></div>'
|
||||||
|
}
|
||||||
|
return string
|
||||||
|
},
|
||||||
|
updateNumbers: function () {
|
||||||
|
var self = Metamaps.Map.InfoBox
|
||||||
|
var mapper = Metamaps.Active.Mapper
|
||||||
|
var relevantPeople = Metamaps.Active.Map.get('permission') === 'commons' ? Metamaps.Mappers : Metamaps.Collaborators
|
||||||
|
|
||||||
|
var contributors_class = ''
|
||||||
|
if (relevantPeople.length === 2) contributors_class = 'multiple mTwo'
|
||||||
|
else if (relevantPeople.length > 2) contributors_class = 'multiple'
|
||||||
|
|
||||||
|
var contributors_image = Metamaps.Erb['user.png']
|
||||||
|
if (relevantPeople.length > 0) {
|
||||||
|
// get the first contributor and use their image
|
||||||
|
contributors_image = relevantPeople.models[0].get('image')
|
||||||
|
}
|
||||||
|
$('.mapContributors img').attr('src', contributors_image).removeClass('multiple mTwo').addClass(contributors_class)
|
||||||
|
$('.mapContributors span').text(relevantPeople.length)
|
||||||
|
$('.mapContributors .tip').html(self.createContributorList())
|
||||||
|
self.addTypeahead()
|
||||||
|
$('.mapContributors .tip').unbind().click(function (event) {
|
||||||
|
event.stopPropagation()
|
||||||
|
})
|
||||||
|
$('.mapTopics').text(Metamaps.Topics.length)
|
||||||
|
$('.mapSynapses').text(Metamaps.Synapses.length)
|
||||||
|
|
||||||
|
$('.mapEditedAt').html('<span>Last edited: </span>' + Metamaps.Util.nowDateFormatted())
|
||||||
|
},
|
||||||
|
onPermissionClick: function (event) {
|
||||||
|
var self = Metamaps.Map.InfoBox
|
||||||
|
|
||||||
|
if (!self.selectingPermission) {
|
||||||
|
self.selectingPermission = true
|
||||||
|
$(this).addClass('minimize') // this line flips the drop down arrow to a pull up arrow
|
||||||
|
if ($(this).hasClass('commons')) {
|
||||||
|
$(this).append('<ul class="permissionSelect"><li class="public"></li><li class="private"></li></ul>')
|
||||||
|
} else if ($(this).hasClass('public')) {
|
||||||
|
$(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="private"></li></ul>')
|
||||||
|
} else if ($(this).hasClass('private')) {
|
||||||
|
$(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="public"></li></ul>')
|
||||||
|
}
|
||||||
|
$('.mapPermission .permissionSelect li').click(self.selectPermission)
|
||||||
|
event.stopPropagation()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
hidePermissionSelect: function () {
|
||||||
|
var self = Metamaps.Map.InfoBox
|
||||||
|
|
||||||
|
self.selectingPermission = false
|
||||||
|
$('.mapPermission').removeClass('minimize') // this line flips the pull up arrow to a drop down arrow
|
||||||
|
$('.mapPermission .permissionSelect').remove()
|
||||||
|
},
|
||||||
|
selectPermission: function (event) {
|
||||||
|
var self = Metamaps.Map.InfoBox
|
||||||
|
|
||||||
|
self.selectingPermission = false
|
||||||
|
var permission = $(this).attr('class')
|
||||||
|
Metamaps.Active.Map.save({
|
||||||
|
permission: permission
|
||||||
|
})
|
||||||
|
Metamaps.Active.Map.updateMapWrapper()
|
||||||
|
shareable = permission === 'private' ? '' : 'shareable'
|
||||||
|
$('.mapPermission').removeClass('commons public private minimize').addClass(permission)
|
||||||
|
$('.mapPermission .permissionSelect').remove()
|
||||||
|
$('.mapInfoBox').removeClass('shareable').addClass(shareable)
|
||||||
|
event.stopPropagation()
|
||||||
|
},
|
||||||
|
deleteActiveMap: function () {
|
||||||
|
var 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.'
|
||||||
|
|
||||||
|
var doIt = confirm(confirmString)
|
||||||
|
var map = Metamaps.Active.Map
|
||||||
|
var mapper = Metamaps.Active.Mapper
|
||||||
|
var authorized = map.authorizePermissionChange(mapper)
|
||||||
|
|
||||||
|
if (doIt && authorized) {
|
||||||
|
Metamaps.Map.InfoBox.close()
|
||||||
|
Metamaps.Maps.Active.remove(map)
|
||||||
|
Metamaps.Maps.Featured.remove(map)
|
||||||
|
Metamaps.Maps.Mine.remove(map)
|
||||||
|
Metamaps.Maps.Shared.remove(map)
|
||||||
|
map.destroy()
|
||||||
|
Metamaps.Router.home()
|
||||||
|
Metamaps.GlobalUI.notifyUser('Map eliminated!')
|
||||||
|
}
|
||||||
|
else if (!authorized) {
|
||||||
|
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?")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}; // end Metamaps.Map.InfoBox
|
20
app/assets/javascripts/src/Metamaps.Mapper.js
Normal file
20
app/assets/javascripts/src/Metamaps.Mapper.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/* global Metamaps, $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Metamaps.Mapper.js.erb
|
||||||
|
*
|
||||||
|
* Dependencies: none!
|
||||||
|
*/
|
||||||
|
|
||||||
|
Metamaps.Mapper = {
|
||||||
|
// this function is to retrieve a mapper JSON object from the database
|
||||||
|
// @param id = the id of the mapper to retrieve
|
||||||
|
get: function (id, callback) {
|
||||||
|
return $.ajax({
|
||||||
|
url: '/users/' + id + '.json',
|
||||||
|
success: function (data) {
|
||||||
|
callback(new Metamaps.Backbone.Mapper(data))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}; // end Metamaps.Mapper
|
117
app/assets/javascripts/src/Metamaps.Organize.js
Normal file
117
app/assets/javascripts/src/Metamaps.Organize.js
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
/* global Metamaps, $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Metamaps.Organize.js.erb
|
||||||
|
*
|
||||||
|
* Dependencies:
|
||||||
|
* - Metamaps.Visualize
|
||||||
|
*/
|
||||||
|
Metamaps.Organize = {
|
||||||
|
init: function () {},
|
||||||
|
arrange: function (layout, centerNode) {
|
||||||
|
// first option for layout to implement is 'grid', will do an evenly spaced grid with its center at the 0,0 origin
|
||||||
|
if (layout == 'grid') {
|
||||||
|
var numNodes = _.size(Metamaps.Visualize.mGraph.graph.nodes); // this will always be an integer, the # of nodes on your graph visualization
|
||||||
|
var numColumns = Math.floor(Math.sqrt(numNodes)) // the number of columns to make an even grid
|
||||||
|
var GRIDSPACE = 400
|
||||||
|
var row = 0
|
||||||
|
var column = 0
|
||||||
|
Metamaps.Visualize.mGraph.graph.eachNode(function (n) {
|
||||||
|
if (column == numColumns) {
|
||||||
|
column = 0
|
||||||
|
row += 1
|
||||||
|
}
|
||||||
|
var newPos = new $jit.Complex()
|
||||||
|
newPos.x = column * GRIDSPACE
|
||||||
|
newPos.y = row * GRIDSPACE
|
||||||
|
n.setPos(newPos, 'end')
|
||||||
|
column += 1
|
||||||
|
})
|
||||||
|
Metamaps.Visualize.mGraph.animate(Metamaps.JIT.ForceDirected.animateSavedLayout)
|
||||||
|
} else if (layout == 'grid_full') {
|
||||||
|
// this will always be an integer, the # of nodes on your graph visualization
|
||||||
|
var numNodes = _.size(Metamaps.Visualize.mGraph.graph.nodes)
|
||||||
|
// var numColumns = Math.floor(Math.sqrt(numNodes)) // the number of columns to make an even grid
|
||||||
|
// var GRIDSPACE = 400
|
||||||
|
var height = Metamaps.Visualize.mGraph.canvas.getSize(0).height
|
||||||
|
var width = Metamaps.Visualize.mGraph.canvas.getSize(0).width
|
||||||
|
var totalArea = height * width
|
||||||
|
var cellArea = totalArea / numNodes
|
||||||
|
var ratio = height / width
|
||||||
|
var cellWidth = sqrt(cellArea / ratio)
|
||||||
|
var cellHeight = cellArea / cellWidth
|
||||||
|
var row = floor(height / cellHeight)
|
||||||
|
var column = floor(width / cellWidth)
|
||||||
|
var totalCells = row * column
|
||||||
|
|
||||||
|
if (totalCells)
|
||||||
|
Metamaps.Visualize.mGraph.graph.eachNode(function (n) {
|
||||||
|
if (column == numColumns) {
|
||||||
|
column = 0
|
||||||
|
row += 1
|
||||||
|
}
|
||||||
|
var newPos = new $jit.Complex()
|
||||||
|
newPos.x = column * GRIDSPACE
|
||||||
|
newPos.y = row * GRIDSPACE
|
||||||
|
n.setPos(newPos, 'end')
|
||||||
|
column += 1
|
||||||
|
})
|
||||||
|
Metamaps.Visualize.mGraph.animate(Metamaps.JIT.ForceDirected.animateSavedLayout)
|
||||||
|
} else if (layout == 'radial') {
|
||||||
|
var centerX = centerNode.getPos().x
|
||||||
|
var centerY = centerNode.getPos().y
|
||||||
|
centerNode.setPos(centerNode.getPos(), 'end')
|
||||||
|
|
||||||
|
console.log(centerNode.adjacencies)
|
||||||
|
var lineLength = 200
|
||||||
|
var usedNodes = {}
|
||||||
|
usedNodes[centerNode.id] = centerNode
|
||||||
|
var radial = function (node, level, degree) {
|
||||||
|
if (level == 1) {
|
||||||
|
var numLinksTemp = _.size(node.adjacencies)
|
||||||
|
var angleTemp = 2 * Math.PI / numLinksTemp
|
||||||
|
} else {
|
||||||
|
angleTemp = 2 * Math.PI / 20
|
||||||
|
}
|
||||||
|
node.eachAdjacency(function (a) {
|
||||||
|
var isSecondLevelNode = (centerNode.adjacencies[a.nodeTo.id] != undefined && level > 1)
|
||||||
|
if (usedNodes[a.nodeTo.id] == undefined && !isSecondLevelNode) {
|
||||||
|
var newPos = new $jit.Complex()
|
||||||
|
newPos.x = level * lineLength * Math.sin(degree) + centerX
|
||||||
|
newPos.y = level * lineLength * Math.cos(degree) + centerY
|
||||||
|
a.nodeTo.setPos(newPos, 'end')
|
||||||
|
usedNodes[a.nodeTo.id] = a.nodeTo
|
||||||
|
|
||||||
|
radial(a.nodeTo, level + 1, degree)
|
||||||
|
degree += angleTemp
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
radial(centerNode, 1, 0)
|
||||||
|
Metamaps.Visualize.mGraph.animate(Metamaps.JIT.ForceDirected.animateSavedLayout)
|
||||||
|
} else if (layout == 'center_viewport') {
|
||||||
|
var lowX = 0,
|
||||||
|
lowY = 0,
|
||||||
|
highX = 0,
|
||||||
|
highY = 0
|
||||||
|
var oldOriginX = Metamaps.Visualize.mGraph.canvas.translateOffsetX
|
||||||
|
var oldOriginY = Metamaps.Visualize.mGraph.canvas.translateOffsetY
|
||||||
|
|
||||||
|
Metamaps.Visualize.mGraph.graph.eachNode(function (n) {
|
||||||
|
if (n.id === 1) {
|
||||||
|
lowX = n.getPos().x
|
||||||
|
lowY = n.getPos().y
|
||||||
|
highX = n.getPos().x
|
||||||
|
highY = n.getPos().y
|
||||||
|
}
|
||||||
|
if (n.getPos().x < lowX) lowX = n.getPos().x
|
||||||
|
if (n.getPos().y < lowY) lowY = n.getPos().y
|
||||||
|
if (n.getPos().x > highX) highX = n.getPos().x
|
||||||
|
if (n.getPos().y > highY) highY = n.getPos().y
|
||||||
|
})
|
||||||
|
console.log(lowX, lowY, highX, highY)
|
||||||
|
var newOriginX = (lowX + highX) / 2
|
||||||
|
var newOriginY = (lowY + highY) / 2
|
||||||
|
} else alert('please call function with a valid layout dammit!')
|
||||||
|
}
|
||||||
|
}; // end Metamaps.Organize
|
1199
app/assets/javascripts/src/Metamaps.Realtime.js
Normal file
1199
app/assets/javascripts/src/Metamaps.Realtime.js
Normal file
File diff suppressed because it is too large
Load diff
|
@ -87,7 +87,7 @@
|
||||||
// either 'featured', 'mapper', or 'active'
|
// either 'featured', 'mapper', or 'active'
|
||||||
var capitalize = section.charAt(0).toUpperCase() + section.slice(1)
|
var capitalize = section.charAt(0).toUpperCase() + section.slice(1)
|
||||||
|
|
||||||
if (section === 'featured' || section === 'active') {
|
if (section === 'shared' || section === 'featured' || section === 'active') {
|
||||||
document.title = 'Explore ' + capitalize + ' Maps | Metamaps'
|
document.title = 'Explore ' + capitalize + ' Maps | Metamaps'
|
||||||
} else if (section === 'mapper') {
|
} else if (section === 'mapper') {
|
||||||
$.ajax({
|
$.ajax({
|
169
app/assets/javascripts/src/Metamaps.Synapse.js
Normal file
169
app/assets/javascripts/src/Metamaps.Synapse.js
Normal file
|
@ -0,0 +1,169 @@
|
||||||
|
/* global Metamaps, $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Metamaps.Synapse.js.erb
|
||||||
|
*
|
||||||
|
* Dependencies:
|
||||||
|
* - Metamaps.Backbone
|
||||||
|
* - Metamaps.Control
|
||||||
|
* - Metamaps.Create
|
||||||
|
* - Metamaps.JIT
|
||||||
|
* - Metamaps.Map
|
||||||
|
* - Metamaps.Mappings
|
||||||
|
* - Metamaps.Selected
|
||||||
|
* - Metamaps.Settings
|
||||||
|
* - Metamaps.Synapses
|
||||||
|
* - Metamaps.Topics
|
||||||
|
* - Metamaps.Visualize
|
||||||
|
*/
|
||||||
|
|
||||||
|
Metamaps.Synapse = {
|
||||||
|
// this function is to retrieve a synapse JSON object from the database
|
||||||
|
// @param id = the id of the synapse to retrieve
|
||||||
|
get: function (id, callback) {
|
||||||
|
// if the desired topic is not yet in the local topic repository, fetch it
|
||||||
|
if (Metamaps.Synapses.get(id) == undefined) {
|
||||||
|
if (!callback) {
|
||||||
|
var e = $.ajax({
|
||||||
|
url: '/synapses/' + id + '.json',
|
||||||
|
async: false
|
||||||
|
})
|
||||||
|
Metamaps.Synapses.add($.parseJSON(e.responseText))
|
||||||
|
return Metamaps.Synapses.get(id)
|
||||||
|
} else {
|
||||||
|
return $.ajax({
|
||||||
|
url: '/synapses/' + id + '.json',
|
||||||
|
success: function (data) {
|
||||||
|
Metamaps.Synapses.add(data)
|
||||||
|
callback(Metamaps.Synapses.get(id))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!callback) {
|
||||||
|
return Metamaps.Synapses.get(id)
|
||||||
|
} else {
|
||||||
|
return callback(Metamaps.Synapses.get(id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
renderSynapse: function (mapping, synapse, node1, node2, createNewInDB) {
|
||||||
|
var self = Metamaps.Synapse
|
||||||
|
|
||||||
|
var edgeOnViz
|
||||||
|
|
||||||
|
var newedge = synapse.createEdge(mapping)
|
||||||
|
|
||||||
|
Metamaps.Visualize.mGraph.graph.addAdjacence(node1, node2, newedge.data)
|
||||||
|
edgeOnViz = Metamaps.Visualize.mGraph.graph.getAdjacence(node1.id, node2.id)
|
||||||
|
synapse.set('edge', edgeOnViz)
|
||||||
|
synapse.updateEdge() // links the synapse and the mapping to the edge
|
||||||
|
|
||||||
|
Metamaps.Control.selectEdge(edgeOnViz)
|
||||||
|
|
||||||
|
var mappingSuccessCallback = function (mappingModel, response) {
|
||||||
|
var newSynapseData = {
|
||||||
|
mappingid: mappingModel.id,
|
||||||
|
mappableid: mappingModel.get('mappable_id')
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).trigger(Metamaps.JIT.events.newSynapse, [newSynapseData])
|
||||||
|
}
|
||||||
|
var synapseSuccessCallback = function (synapseModel, response) {
|
||||||
|
if (Metamaps.Active.Map) {
|
||||||
|
mapping.save({ mappable_id: synapseModel.id }, {
|
||||||
|
success: mappingSuccessCallback
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Metamaps.Settings.sandbox && createNewInDB) {
|
||||||
|
if (synapse.isNew()) {
|
||||||
|
synapse.save(null, {
|
||||||
|
success: synapseSuccessCallback,
|
||||||
|
error: function (model, response) {
|
||||||
|
console.log('error saving synapse to database')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else if (!synapse.isNew() && Metamaps.Active.Map) {
|
||||||
|
mapping.save(null, {
|
||||||
|
success: mappingSuccessCallback
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
createSynapseLocally: function () {
|
||||||
|
var self = Metamaps.Synapse,
|
||||||
|
topic1,
|
||||||
|
topic2,
|
||||||
|
node1,
|
||||||
|
node2,
|
||||||
|
synapse,
|
||||||
|
mapping
|
||||||
|
|
||||||
|
$(document).trigger(Metamaps.Map.events.editedByActiveMapper)
|
||||||
|
|
||||||
|
// for each node in this array we will create a synapse going to the position2 node.
|
||||||
|
var synapsesToCreate = []
|
||||||
|
|
||||||
|
topic2 = Metamaps.Topics.get(Metamaps.Create.newSynapse.topic2id)
|
||||||
|
node2 = topic2.get('node')
|
||||||
|
|
||||||
|
var len = Metamaps.Selected.Nodes.length
|
||||||
|
if (len == 0) {
|
||||||
|
topic1 = Metamaps.Topics.get(Metamaps.Create.newSynapse.topic1id)
|
||||||
|
synapsesToCreate[0] = topic1.get('node')
|
||||||
|
} else if (len > 0) {
|
||||||
|
synapsesToCreate = Metamaps.Selected.Nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < synapsesToCreate.length; i++) {
|
||||||
|
node1 = synapsesToCreate[i]
|
||||||
|
topic1 = node1.getData('topic')
|
||||||
|
synapse = new Metamaps.Backbone.Synapse({
|
||||||
|
desc: Metamaps.Create.newSynapse.description,
|
||||||
|
node1_id: topic1.isNew() ? topic1.cid : topic1.id,
|
||||||
|
node2_id: topic2.isNew() ? topic2.cid : topic2.id,
|
||||||
|
})
|
||||||
|
Metamaps.Synapses.add(synapse)
|
||||||
|
|
||||||
|
mapping = new Metamaps.Backbone.Mapping({
|
||||||
|
mappable_type: 'Synapse',
|
||||||
|
mappable_id: synapse.cid,
|
||||||
|
})
|
||||||
|
Metamaps.Mappings.add(mapping)
|
||||||
|
|
||||||
|
// this function also includes the creation of the synapse in the database
|
||||||
|
self.renderSynapse(mapping, synapse, node1, node2, true)
|
||||||
|
} // for each in synapsesToCreate
|
||||||
|
|
||||||
|
Metamaps.Create.newSynapse.hide()
|
||||||
|
},
|
||||||
|
getSynapseFromAutocomplete: function (id) {
|
||||||
|
var self = Metamaps.Synapse,
|
||||||
|
topic1,
|
||||||
|
topic2,
|
||||||
|
node1,
|
||||||
|
node2
|
||||||
|
|
||||||
|
var synapse = self.get(id)
|
||||||
|
|
||||||
|
var mapping = new Metamaps.Backbone.Mapping({
|
||||||
|
mappable_type: 'Synapse',
|
||||||
|
mappable_id: synapse.id,
|
||||||
|
})
|
||||||
|
Metamaps.Mappings.add(mapping)
|
||||||
|
|
||||||
|
topic1 = Metamaps.Topics.get(Metamaps.Create.newSynapse.topic1id)
|
||||||
|
node1 = topic1.get('node')
|
||||||
|
topic2 = Metamaps.Topics.get(Metamaps.Create.newSynapse.topic2id)
|
||||||
|
node2 = topic2.get('node')
|
||||||
|
Metamaps.Create.newSynapse.hide()
|
||||||
|
|
||||||
|
self.renderSynapse(mapping, synapse, node1, node2, true)
|
||||||
|
}
|
||||||
|
}; // end Metamaps.Synapse
|
288
app/assets/javascripts/src/Metamaps.SynapseCard.js
Normal file
288
app/assets/javascripts/src/Metamaps.SynapseCard.js
Normal file
|
@ -0,0 +1,288 @@
|
||||||
|
/* global Metamaps, $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Metamaps.SynapseCard.js
|
||||||
|
*
|
||||||
|
* Dependencies:
|
||||||
|
* - Metamaps.Active
|
||||||
|
* - Metamaps.Control
|
||||||
|
* - Metamaps.Mapper
|
||||||
|
* - Metamaps.Visualize
|
||||||
|
*/
|
||||||
|
Metamaps.SynapseCard = {
|
||||||
|
openSynapseCard: null,
|
||||||
|
showCard: function (edge, e) {
|
||||||
|
var self = Metamaps.SynapseCard
|
||||||
|
|
||||||
|
// reset so we don't interfere with other edges, but first, save its x and y
|
||||||
|
var myX = $('#edit_synapse').css('left')
|
||||||
|
var myY = $('#edit_synapse').css('top')
|
||||||
|
$('#edit_synapse').remove()
|
||||||
|
|
||||||
|
// so label is missing while editing
|
||||||
|
Metamaps.Control.deselectEdge(edge)
|
||||||
|
|
||||||
|
var index = edge.getData('displayIndex') ? edge.getData('displayIndex') : 0
|
||||||
|
var synapse = edge.getData('synapses')[index]; // for now, just get the first synapse
|
||||||
|
|
||||||
|
// create the wrapper around the form elements, including permissions
|
||||||
|
// classes to make best_in_place happy
|
||||||
|
var edit_div = document.createElement('div')
|
||||||
|
edit_div.innerHTML = '<div id="editSynUpperBar"></div><div id="editSynLowerBar"></div>'
|
||||||
|
edit_div.setAttribute('id', 'edit_synapse')
|
||||||
|
if (synapse.authorizeToEdit(Metamaps.Active.Mapper)) {
|
||||||
|
edit_div.className = 'permission canEdit'
|
||||||
|
edit_div.className += synapse.authorizePermissionChange(Metamaps.Active.Mapper) ? ' yourEdge' : ''
|
||||||
|
} else {
|
||||||
|
edit_div.className = 'permission cannotEdit'
|
||||||
|
}
|
||||||
|
$('#wrapper').append(edit_div)
|
||||||
|
|
||||||
|
self.populateShowCard(edge, synapse)
|
||||||
|
|
||||||
|
// drop it in the right spot, activate it
|
||||||
|
$('#edit_synapse').css('position', 'absolute')
|
||||||
|
if (e) {
|
||||||
|
$('#edit_synapse').css('left', e.clientX)
|
||||||
|
$('#edit_synapse').css('top', e.clientY)
|
||||||
|
} else {
|
||||||
|
$('#edit_synapse').css('left', myX)
|
||||||
|
$('#edit_synapse').css('top', myY)
|
||||||
|
}
|
||||||
|
// $('#edit_synapse_name').click() //required in case name is empty
|
||||||
|
// $('#edit_synapse_name input').focus()
|
||||||
|
$('#edit_synapse').show()
|
||||||
|
|
||||||
|
self.openSynapseCard = edge
|
||||||
|
},
|
||||||
|
|
||||||
|
hideCard: function () {
|
||||||
|
$('#edit_synapse').remove()
|
||||||
|
Metamaps.SynapseCard.openSynapseCard = null
|
||||||
|
},
|
||||||
|
|
||||||
|
populateShowCard: function (edge, synapse) {
|
||||||
|
var self = Metamaps.SynapseCard
|
||||||
|
|
||||||
|
self.add_synapse_count(edge)
|
||||||
|
self.add_desc_form(synapse)
|
||||||
|
self.add_drop_down(edge, synapse)
|
||||||
|
self.add_user_info(synapse)
|
||||||
|
self.add_perms_form(synapse)
|
||||||
|
self.add_direction_form(synapse)
|
||||||
|
},
|
||||||
|
add_synapse_count: function (edge) {
|
||||||
|
var count = edge.getData('synapses').length
|
||||||
|
|
||||||
|
$('#editSynUpperBar').append('<div id="synapseCardCount">' + count + '</div>')
|
||||||
|
},
|
||||||
|
add_desc_form: function (synapse) {
|
||||||
|
var data_nil = 'Click to add description.'
|
||||||
|
|
||||||
|
// TODO make it so that this would work even in sandbox mode,
|
||||||
|
// currently with Best_in_place it won't
|
||||||
|
|
||||||
|
// desc editing form
|
||||||
|
$('#editSynUpperBar').append('<div id="edit_synapse_desc"></div>')
|
||||||
|
$('#edit_synapse_desc').attr('class', 'best_in_place best_in_place_desc')
|
||||||
|
$('#edit_synapse_desc').attr('data-object', 'synapse')
|
||||||
|
$('#edit_synapse_desc').attr('data-attribute', 'desc')
|
||||||
|
$('#edit_synapse_desc').attr('data-type', 'textarea')
|
||||||
|
$('#edit_synapse_desc').attr('data-nil', data_nil)
|
||||||
|
$('#edit_synapse_desc').attr('data-url', '/synapses/' + synapse.id)
|
||||||
|
$('#edit_synapse_desc').html(synapse.get('desc'))
|
||||||
|
|
||||||
|
// if edge data is blank or just whitespace, populate it with data_nil
|
||||||
|
if ($('#edit_synapse_desc').html().trim() == '') {
|
||||||
|
if (synapse.authorizeToEdit(Metamaps.Active.Mapper)) {
|
||||||
|
$('#edit_synapse_desc').html(data_nil)
|
||||||
|
} else {
|
||||||
|
$('#edit_synapse_desc').html('(no description)')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#edit_synapse_desc').bind('ajax:success', function () {
|
||||||
|
var desc = $(this).html()
|
||||||
|
if (desc == data_nil) {
|
||||||
|
synapse.set('desc', '')
|
||||||
|
} else {
|
||||||
|
synapse.set('desc', desc)
|
||||||
|
}
|
||||||
|
synapse.trigger('saved')
|
||||||
|
Metamaps.Control.selectEdge(synapse.get('edge'))
|
||||||
|
Metamaps.Visualize.mGraph.plot()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
add_drop_down: function (edge, synapse) {
|
||||||
|
var list, i, synapses, l, desc
|
||||||
|
|
||||||
|
synapses = edge.getData('synapses')
|
||||||
|
l = synapses.length
|
||||||
|
|
||||||
|
if (l > 1) {
|
||||||
|
// append the element that you click to show dropdown select
|
||||||
|
$('#editSynUpperBar').append('<div id="dropdownSynapses"></div>')
|
||||||
|
$('#dropdownSynapses').click(function (e) {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation() // stop it from immediately closing it again
|
||||||
|
$('#switchSynapseList').toggle()
|
||||||
|
})
|
||||||
|
// hide the dropdown again if you click anywhere else on the synapse card
|
||||||
|
$('#edit_synapse').click(function () {
|
||||||
|
$('#switchSynapseList').hide()
|
||||||
|
})
|
||||||
|
|
||||||
|
// generate the list of other synapses
|
||||||
|
list = '<ul id="switchSynapseList">'
|
||||||
|
for (i = 0; i < l; i++) {
|
||||||
|
if (synapses[i] !== synapse) { // don't add the current one to the list
|
||||||
|
desc = synapses[i].get('desc')
|
||||||
|
desc = desc === '' || desc === null ? '(no description)' : desc
|
||||||
|
list += '<li data-synapse-index="' + i + '">' + desc + '</li>'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list += '</ul>'
|
||||||
|
// add the list of the other synapses
|
||||||
|
$('#editSynLowerBar').append(list)
|
||||||
|
|
||||||
|
// attach click listeners to list items that
|
||||||
|
// will cause it to switch the displayed synapse
|
||||||
|
// when you click it
|
||||||
|
$('#switchSynapseList li').click(function (e) {
|
||||||
|
e.stopPropagation()
|
||||||
|
var index = parseInt($(this).attr('data-synapse-index'))
|
||||||
|
edge.setData('displayIndex', index)
|
||||||
|
Metamaps.Visualize.mGraph.plot()
|
||||||
|
Metamaps.SynapseCard.showCard(edge, false)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
add_user_info: function (synapse) {
|
||||||
|
var u = '<div id="edgeUser" class="hoverForTip">'
|
||||||
|
u += '<a href="/explore/mapper/' + synapse.get('user_id') + '"> <img src="" width="24" height="24" /></a>'
|
||||||
|
u += '<div class="tip">' + synapse.get('user_name') + '</div></div>'
|
||||||
|
$('#editSynLowerBar').append(u)
|
||||||
|
|
||||||
|
// get mapper image
|
||||||
|
var setMapperImage = function (mapper) {
|
||||||
|
$('#edgeUser img').attr('src', mapper.get('image'))
|
||||||
|
}
|
||||||
|
Metamaps.Mapper.get(synapse.get('user_id'), setMapperImage)
|
||||||
|
},
|
||||||
|
|
||||||
|
add_perms_form: function (synapse) {
|
||||||
|
// permissions - if owner, also allow permission editing
|
||||||
|
$('#editSynLowerBar').append('<div class="mapPerm ' + synapse.get('calculated_permission').substring(0, 2) + '"></div>')
|
||||||
|
|
||||||
|
// ability to change permission
|
||||||
|
var selectingPermission = false
|
||||||
|
var permissionLiClick = function (event) {
|
||||||
|
selectingPermission = false
|
||||||
|
var permission = $(this).attr('class')
|
||||||
|
synapse.save({
|
||||||
|
permission: permission,
|
||||||
|
defer_to_map_id: null
|
||||||
|
})
|
||||||
|
$('#edit_synapse .mapPerm').removeClass('co pu pr minimize').addClass(permission.substring(0, 2))
|
||||||
|
$('#edit_synapse .permissionSelect').remove()
|
||||||
|
event.stopPropagation()
|
||||||
|
}
|
||||||
|
|
||||||
|
var openPermissionSelect = function (event) {
|
||||||
|
if (!selectingPermission) {
|
||||||
|
selectingPermission = true
|
||||||
|
$(this).addClass('minimize') // this line flips the drop down arrow to a pull up arrow
|
||||||
|
if ($(this).hasClass('co')) {
|
||||||
|
$(this).append('<ul class="permissionSelect"><li class="public"></li><li class="private"></li></ul>')
|
||||||
|
} else if ($(this).hasClass('pu')) {
|
||||||
|
$(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="private"></li></ul>')
|
||||||
|
} else if ($(this).hasClass('pr')) {
|
||||||
|
$(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="public"></li></ul>')
|
||||||
|
}
|
||||||
|
$('#edit_synapse .permissionSelect li').click(permissionLiClick)
|
||||||
|
event.stopPropagation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var hidePermissionSelect = function () {
|
||||||
|
selectingPermission = false
|
||||||
|
$('#edit_synapse.yourEdge .mapPerm').removeClass('minimize') // this line flips the pull up arrow to a drop down arrow
|
||||||
|
$('#edit_synapse .permissionSelect').remove()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (synapse.authorizePermissionChange(Metamaps.Active.Mapper)) {
|
||||||
|
$('#edit_synapse.yourEdge .mapPerm').click(openPermissionSelect)
|
||||||
|
$('#edit_synapse').click(hidePermissionSelect)
|
||||||
|
}
|
||||||
|
}, // add_perms_form
|
||||||
|
|
||||||
|
add_direction_form: function (synapse) {
|
||||||
|
// directionality checkboxes
|
||||||
|
$('#editSynLowerBar').append('<div id="edit_synapse_left"></div>')
|
||||||
|
$('#editSynLowerBar').append('<div id="edit_synapse_right"></div>')
|
||||||
|
|
||||||
|
var edge = synapse.get('edge')
|
||||||
|
|
||||||
|
// determine which node is to the left and the right
|
||||||
|
// if directly in a line, top is left
|
||||||
|
if (edge.nodeFrom.pos.x < edge.nodeTo.pos.x ||
|
||||||
|
edge.nodeFrom.pos.x == edge.nodeTo.pos.x &&
|
||||||
|
edge.nodeFrom.pos.y < edge.nodeTo.pos.y) {
|
||||||
|
var left = edge.nodeTo.getData('topic')
|
||||||
|
var right = edge.nodeFrom.getData('topic')
|
||||||
|
} else {
|
||||||
|
var left = edge.nodeFrom.getData('topic')
|
||||||
|
var right = edge.nodeTo.getData('topic')
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* One node is actually on the left onscreen. Call it left, & the other right.
|
||||||
|
* If category is from-to, and that node is first, check the 'right' checkbox.
|
||||||
|
* Else check the 'left' checkbox since the arrow is incoming.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var directionCat = synapse.get('category'); // both, none, from-to
|
||||||
|
if (directionCat == 'from-to') {
|
||||||
|
var from_to = [synapse.get('node1_id'), synapse.get('node2_id')]
|
||||||
|
if (from_to[0] == left.id) {
|
||||||
|
// check left checkbox
|
||||||
|
$('#edit_synapse_left').addClass('checked')
|
||||||
|
} else {
|
||||||
|
// check right checkbox
|
||||||
|
$('#edit_synapse_right').addClass('checked')
|
||||||
|
}
|
||||||
|
} else if (directionCat == 'both') {
|
||||||
|
// check both checkboxes
|
||||||
|
$('#edit_synapse_left').addClass('checked')
|
||||||
|
$('#edit_synapse_right').addClass('checked')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (synapse.authorizeToEdit(Metamaps.Active.Mapper)) {
|
||||||
|
$('#edit_synapse_left, #edit_synapse_right').click(function () {
|
||||||
|
$(this).toggleClass('checked')
|
||||||
|
|
||||||
|
var leftChecked = $('#edit_synapse_left').is('.checked')
|
||||||
|
var rightChecked = $('#edit_synapse_right').is('.checked')
|
||||||
|
|
||||||
|
var dir = synapse.getDirection()
|
||||||
|
var dirCat = 'none'
|
||||||
|
if (leftChecked && rightChecked) {
|
||||||
|
dirCat = 'both'
|
||||||
|
} else if (!leftChecked && rightChecked) {
|
||||||
|
dirCat = 'from-to'
|
||||||
|
dir = [right.id, left.id]
|
||||||
|
} else if (leftChecked && !rightChecked) {
|
||||||
|
dirCat = 'from-to'
|
||||||
|
dir = [left.id, right.id]
|
||||||
|
}
|
||||||
|
|
||||||
|
synapse.save({
|
||||||
|
category: dirCat,
|
||||||
|
node1_id: dir[0],
|
||||||
|
node2_id: dir[1]
|
||||||
|
})
|
||||||
|
Metamaps.Visualize.mGraph.plot()
|
||||||
|
})
|
||||||
|
} // if
|
||||||
|
} // add_direction_form
|
||||||
|
}; // end Metamaps.SynapseCard
|
363
app/assets/javascripts/src/Metamaps.Topic.js
Normal file
363
app/assets/javascripts/src/Metamaps.Topic.js
Normal file
|
@ -0,0 +1,363 @@
|
||||||
|
/* global Metamaps, $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Metamaps.Topic.js.erb
|
||||||
|
*
|
||||||
|
* Dependencies:
|
||||||
|
* - Metamaps.Active
|
||||||
|
* - Metamaps.Backbone
|
||||||
|
* - Metamaps.Backbone
|
||||||
|
* - Metamaps.Create
|
||||||
|
* - Metamaps.Creators
|
||||||
|
* - Metamaps.Famous
|
||||||
|
* - Metamaps.Filter
|
||||||
|
* - Metamaps.GlobalUI
|
||||||
|
* - Metamaps.JIT
|
||||||
|
* - Metamaps.Mappings
|
||||||
|
* - Metamaps.Selected
|
||||||
|
* - Metamaps.Settings
|
||||||
|
* - Metamaps.SynapseCard
|
||||||
|
* - Metamaps.Synapses
|
||||||
|
* - Metamaps.TopicCard
|
||||||
|
* - Metamaps.Topics
|
||||||
|
* - Metamaps.Util
|
||||||
|
* - Metamaps.Visualize
|
||||||
|
* - Metamaps.tempInit
|
||||||
|
* - Metamaps.tempNode
|
||||||
|
* - Metamaps.tempNode2
|
||||||
|
*/
|
||||||
|
|
||||||
|
Metamaps.Topic = {
|
||||||
|
// this function is to retrieve a topic JSON object from the database
|
||||||
|
// @param id = the id of the topic to retrieve
|
||||||
|
get: function (id, callback) {
|
||||||
|
// if the desired topic is not yet in the local topic repository, fetch it
|
||||||
|
if (Metamaps.Topics.get(id) == undefined) {
|
||||||
|
// console.log("Ajax call!")
|
||||||
|
if (!callback) {
|
||||||
|
var e = $.ajax({
|
||||||
|
url: '/topics/' + id + '.json',
|
||||||
|
async: false
|
||||||
|
})
|
||||||
|
Metamaps.Topics.add($.parseJSON(e.responseText))
|
||||||
|
return Metamaps.Topics.get(id)
|
||||||
|
} else {
|
||||||
|
return $.ajax({
|
||||||
|
url: '/topics/' + id + '.json',
|
||||||
|
success: function (data) {
|
||||||
|
Metamaps.Topics.add(data)
|
||||||
|
callback(Metamaps.Topics.get(id))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!callback) {
|
||||||
|
return Metamaps.Topics.get(id)
|
||||||
|
} else {
|
||||||
|
return callback(Metamaps.Topics.get(id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
launch: function (id) {
|
||||||
|
var bb = Metamaps.Backbone
|
||||||
|
var start = function (data) {
|
||||||
|
Metamaps.Active.Topic = new bb.Topic(data.topic)
|
||||||
|
Metamaps.Creators = new bb.MapperCollection(data.creators)
|
||||||
|
Metamaps.Topics = new bb.TopicCollection([data.topic].concat(data.relatives))
|
||||||
|
Metamaps.Synapses = new bb.SynapseCollection(data.synapses)
|
||||||
|
Metamaps.Backbone.attachCollectionEvents()
|
||||||
|
|
||||||
|
// set filter mapper H3 text
|
||||||
|
$('#filter_by_mapper h3').html('CREATORS')
|
||||||
|
|
||||||
|
// build and render the visualization
|
||||||
|
Metamaps.Visualize.type = 'RGraph'
|
||||||
|
Metamaps.JIT.prepareVizData()
|
||||||
|
|
||||||
|
// update filters
|
||||||
|
Metamaps.Filter.reset()
|
||||||
|
|
||||||
|
// reset selected arrays
|
||||||
|
Metamaps.Selected.reset()
|
||||||
|
|
||||||
|
// these three update the actual filter box with the right list items
|
||||||
|
Metamaps.Filter.checkMetacodes()
|
||||||
|
Metamaps.Filter.checkSynapses()
|
||||||
|
Metamaps.Filter.checkMappers()
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/topics/' + id + '/network.json',
|
||||||
|
success: start
|
||||||
|
})
|
||||||
|
},
|
||||||
|
end: function () {
|
||||||
|
if (Metamaps.Active.Topic) {
|
||||||
|
$('.rightclickmenu').remove()
|
||||||
|
Metamaps.TopicCard.hideCard()
|
||||||
|
Metamaps.SynapseCard.hideCard()
|
||||||
|
Metamaps.Filter.close()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
centerOn: function (nodeid) {
|
||||||
|
if (!Metamaps.Visualize.mGraph.busy) {
|
||||||
|
Metamaps.Visualize.mGraph.onClick(nodeid, {
|
||||||
|
hideLabels: false,
|
||||||
|
duration: 1000,
|
||||||
|
onComplete: function () {}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fetchRelatives: function (node, metacode_id) {
|
||||||
|
var topics = Metamaps.Topics.map(function (t) { return t.id })
|
||||||
|
var topics_string = topics.join()
|
||||||
|
|
||||||
|
var creators = Metamaps.Creators.map(function (t) { return t.id })
|
||||||
|
var creators_string = creators.join()
|
||||||
|
|
||||||
|
var topic = node.getData('topic')
|
||||||
|
|
||||||
|
var successCallback = function (data) {
|
||||||
|
if (data.creators.length > 0) Metamaps.Creators.add(data.creators)
|
||||||
|
if (data.topics.length > 0) Metamaps.Topics.add(data.topics)
|
||||||
|
if (data.synapses.length > 0) Metamaps.Synapses.add(data.synapses)
|
||||||
|
|
||||||
|
var topicColl = new Metamaps.Backbone.TopicCollection(data.topics)
|
||||||
|
topicColl.add(topic)
|
||||||
|
var synapseColl = new Metamaps.Backbone.SynapseCollection(data.synapses)
|
||||||
|
|
||||||
|
var graph = Metamaps.JIT.convertModelsToJIT(topicColl, synapseColl)[0]
|
||||||
|
Metamaps.Visualize.mGraph.op.sum(graph, {
|
||||||
|
type: 'fade',
|
||||||
|
duration: 500,
|
||||||
|
hideLabels: false
|
||||||
|
})
|
||||||
|
|
||||||
|
var i, l, t, s
|
||||||
|
|
||||||
|
Metamaps.Visualize.mGraph.graph.eachNode(function (n) {
|
||||||
|
t = Metamaps.Topics.get(n.id)
|
||||||
|
t.set({ node: n }, { silent: true })
|
||||||
|
t.updateNode()
|
||||||
|
|
||||||
|
n.eachAdjacency(function (edge) {
|
||||||
|
if (!edge.getData('init')) {
|
||||||
|
edge.setData('init', true)
|
||||||
|
|
||||||
|
l = edge.getData('synapseIDs').length
|
||||||
|
for (i = 0; i < l; i++) {
|
||||||
|
s = Metamaps.Synapses.get(edge.getData('synapseIDs')[i])
|
||||||
|
s.set({ edge: edge }, { silent: true })
|
||||||
|
s.updateEdge()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var paramsString = metacode_id ? 'metacode=' + metacode_id + '&' : ''
|
||||||
|
paramsString += 'network=' + topics_string + '&creators=' + creators_string
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: 'Get',
|
||||||
|
url: '/topics/' + topic.id + '/relatives.json?' + paramsString,
|
||||||
|
success: successCallback,
|
||||||
|
error: function () {}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
renderTopic: function (mapping, topic, createNewInDB, permitCreateSynapseAfter) {
|
||||||
|
var self = Metamaps.Topic
|
||||||
|
|
||||||
|
var nodeOnViz, tempPos
|
||||||
|
|
||||||
|
var newnode = topic.createNode()
|
||||||
|
|
||||||
|
var midpoint = {}, pixelPos
|
||||||
|
|
||||||
|
if (!$.isEmptyObject(Metamaps.Visualize.mGraph.graph.nodes)) {
|
||||||
|
Metamaps.Visualize.mGraph.graph.addNode(newnode)
|
||||||
|
nodeOnViz = Metamaps.Visualize.mGraph.graph.getNode(newnode.id)
|
||||||
|
topic.set('node', nodeOnViz, {silent: true})
|
||||||
|
topic.updateNode() // links the topic and the mapping to the node
|
||||||
|
|
||||||
|
nodeOnViz.setData('dim', 1, 'start')
|
||||||
|
nodeOnViz.setData('dim', 25, 'end')
|
||||||
|
if (Metamaps.Visualize.type === 'RGraph') {
|
||||||
|
tempPos = new $jit.Complex(mapping.get('xloc'), mapping.get('yloc'))
|
||||||
|
tempPos = tempPos.toPolar()
|
||||||
|
nodeOnViz.setPos(tempPos, 'current')
|
||||||
|
nodeOnViz.setPos(tempPos, 'start')
|
||||||
|
nodeOnViz.setPos(tempPos, 'end')
|
||||||
|
} else if (Metamaps.Visualize.type === 'ForceDirected') {
|
||||||
|
nodeOnViz.setPos(new $jit.Complex(mapping.get('xloc'), mapping.get('yloc')), 'current')
|
||||||
|
nodeOnViz.setPos(new $jit.Complex(mapping.get('xloc'), mapping.get('yloc')), 'start')
|
||||||
|
nodeOnViz.setPos(new $jit.Complex(mapping.get('xloc'), mapping.get('yloc')), 'end')
|
||||||
|
}
|
||||||
|
if (Metamaps.Create.newTopic.addSynapse && permitCreateSynapseAfter) {
|
||||||
|
Metamaps.Create.newSynapse.topic1id = Metamaps.tempNode.getData('topic').id
|
||||||
|
|
||||||
|
// position the form
|
||||||
|
midpoint.x = Metamaps.tempNode.pos.getc().x + (nodeOnViz.pos.getc().x - Metamaps.tempNode.pos.getc().x) / 2
|
||||||
|
midpoint.y = Metamaps.tempNode.pos.getc().y + (nodeOnViz.pos.getc().y - Metamaps.tempNode.pos.getc().y) / 2
|
||||||
|
pixelPos = Metamaps.Util.coordsToPixels(midpoint)
|
||||||
|
$('#new_synapse').css('left', pixelPos.x + 'px')
|
||||||
|
$('#new_synapse').css('top', pixelPos.y + 'px')
|
||||||
|
// show the form
|
||||||
|
Metamaps.Create.newSynapse.open()
|
||||||
|
Metamaps.Visualize.mGraph.fx.animate({
|
||||||
|
modes: ['node-property:dim'],
|
||||||
|
duration: 500,
|
||||||
|
onComplete: function () {
|
||||||
|
Metamaps.tempNode = null
|
||||||
|
Metamaps.tempNode2 = null
|
||||||
|
Metamaps.tempInit = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Metamaps.Visualize.mGraph.fx.plotNode(nodeOnViz, Metamaps.Visualize.mGraph.canvas)
|
||||||
|
Metamaps.Visualize.mGraph.fx.animate({
|
||||||
|
modes: ['node-property:dim'],
|
||||||
|
duration: 500,
|
||||||
|
onComplete: function () {}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Metamaps.Visualize.mGraph.loadJSON(newnode)
|
||||||
|
nodeOnViz = Metamaps.Visualize.mGraph.graph.getNode(newnode.id)
|
||||||
|
topic.set('node', nodeOnViz, {silent: true})
|
||||||
|
topic.updateNode() // links the topic and the mapping to the node
|
||||||
|
|
||||||
|
nodeOnViz.setData('dim', 1, 'start')
|
||||||
|
nodeOnViz.setData('dim', 25, 'end')
|
||||||
|
nodeOnViz.setPos(new $jit.Complex(mapping.get('xloc'), mapping.get('yloc')), 'current')
|
||||||
|
nodeOnViz.setPos(new $jit.Complex(mapping.get('xloc'), mapping.get('yloc')), 'start')
|
||||||
|
nodeOnViz.setPos(new $jit.Complex(mapping.get('xloc'), mapping.get('yloc')), 'end')
|
||||||
|
Metamaps.Visualize.mGraph.fx.plotNode(nodeOnViz, Metamaps.Visualize.mGraph.canvas)
|
||||||
|
Metamaps.Visualize.mGraph.fx.animate({
|
||||||
|
modes: ['node-property:dim'],
|
||||||
|
duration: 500,
|
||||||
|
onComplete: function () {}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var mappingSuccessCallback = function (mappingModel, response) {
|
||||||
|
var newTopicData = {
|
||||||
|
mappingid: mappingModel.id,
|
||||||
|
mappableid: mappingModel.get('mappable_id')
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).trigger(Metamaps.JIT.events.newTopic, [newTopicData])
|
||||||
|
}
|
||||||
|
var topicSuccessCallback = function (topicModel, response) {
|
||||||
|
if (Metamaps.Active.Map) {
|
||||||
|
mapping.save({ mappable_id: topicModel.id }, {
|
||||||
|
success: mappingSuccessCallback,
|
||||||
|
error: function (model, response) {
|
||||||
|
console.log('error saving mapping to database')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Metamaps.Create.newTopic.addSynapse) {
|
||||||
|
Metamaps.Create.newSynapse.topic2id = topicModel.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Metamaps.Settings.sandbox && createNewInDB) {
|
||||||
|
if (topic.isNew()) {
|
||||||
|
topic.save(null, {
|
||||||
|
success: topicSuccessCallback,
|
||||||
|
error: function (model, response) {
|
||||||
|
console.log('error saving topic to database')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else if (!topic.isNew() && Metamaps.Active.Map) {
|
||||||
|
mapping.save(null, {
|
||||||
|
success: mappingSuccessCallback
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
createTopicLocally: function () {
|
||||||
|
var self = Metamaps.Topic
|
||||||
|
|
||||||
|
if (Metamaps.Create.newTopic.name === '') {
|
||||||
|
Metamaps.GlobalUI.notifyUser('Please enter a topic title...')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// hide the 'double-click to add a topic' message
|
||||||
|
Metamaps.Famous.viz.hideInstructions()
|
||||||
|
|
||||||
|
$(document).trigger(Metamaps.Map.events.editedByActiveMapper)
|
||||||
|
|
||||||
|
var metacode = Metamaps.Metacodes.get(Metamaps.Create.newTopic.metacode)
|
||||||
|
|
||||||
|
var topic = new Metamaps.Backbone.Topic({
|
||||||
|
name: Metamaps.Create.newTopic.name,
|
||||||
|
metacode_id: metacode.id,
|
||||||
|
defer_to_map_id: Metamaps.Active.Map.id
|
||||||
|
})
|
||||||
|
Metamaps.Topics.add(topic)
|
||||||
|
|
||||||
|
var mapping = new Metamaps.Backbone.Mapping({
|
||||||
|
xloc: Metamaps.Create.newTopic.x,
|
||||||
|
yloc: Metamaps.Create.newTopic.y,
|
||||||
|
mappable_id: topic.cid,
|
||||||
|
mappable_type: 'Topic',
|
||||||
|
})
|
||||||
|
Metamaps.Mappings.add(mapping)
|
||||||
|
|
||||||
|
// these can't happen until the value is retrieved, which happens in the line above
|
||||||
|
Metamaps.Create.newTopic.hide()
|
||||||
|
|
||||||
|
self.renderTopic(mapping, topic, true, true) // this function also includes the creation of the topic in the database
|
||||||
|
},
|
||||||
|
getTopicFromAutocomplete: function (id) {
|
||||||
|
var self = Metamaps.Topic
|
||||||
|
|
||||||
|
$(document).trigger(Metamaps.Map.events.editedByActiveMapper)
|
||||||
|
|
||||||
|
Metamaps.Create.newTopic.hide()
|
||||||
|
|
||||||
|
var topic = self.get(id)
|
||||||
|
|
||||||
|
var mapping = new Metamaps.Backbone.Mapping({
|
||||||
|
xloc: Metamaps.Create.newTopic.x,
|
||||||
|
yloc: Metamaps.Create.newTopic.y,
|
||||||
|
mappable_type: 'Topic',
|
||||||
|
mappable_id: topic.id,
|
||||||
|
})
|
||||||
|
Metamaps.Mappings.add(mapping)
|
||||||
|
|
||||||
|
self.renderTopic(mapping, topic, true, true)
|
||||||
|
},
|
||||||
|
getTopicFromSearch: function (event, id) {
|
||||||
|
var self = Metamaps.Topic
|
||||||
|
|
||||||
|
$(document).trigger(Metamaps.Map.events.editedByActiveMapper)
|
||||||
|
|
||||||
|
var topic = self.get(id)
|
||||||
|
|
||||||
|
var nextCoords = Metamaps.Map.getNextCoord()
|
||||||
|
var mapping = new Metamaps.Backbone.Mapping({
|
||||||
|
xloc: nextCoords.x,
|
||||||
|
yloc: nextCoords.y,
|
||||||
|
mappable_type: 'Topic',
|
||||||
|
mappable_id: topic.id,
|
||||||
|
})
|
||||||
|
Metamaps.Mappings.add(mapping)
|
||||||
|
|
||||||
|
self.renderTopic(mapping, topic, true, true)
|
||||||
|
|
||||||
|
Metamaps.GlobalUI.notifyUser('Topic was added to your map!')
|
||||||
|
|
||||||
|
event.stopPropagation()
|
||||||
|
event.preventDefault()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}; // end Metamaps.Topic
|
451
app/assets/javascripts/src/Metamaps.TopicCard.js
Normal file
451
app/assets/javascripts/src/Metamaps.TopicCard.js
Normal file
|
@ -0,0 +1,451 @@
|
||||||
|
/* global Metamaps, $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Metamaps.TopicCard.js
|
||||||
|
*
|
||||||
|
* Dependencies:
|
||||||
|
* - Metamaps.Active
|
||||||
|
* - Metamaps.GlobalUI
|
||||||
|
* - Metamaps.Mapper
|
||||||
|
* - Metamaps.Metacodes
|
||||||
|
* - Metamaps.Router
|
||||||
|
* - Metamaps.Util
|
||||||
|
* - Metamaps.Visualize
|
||||||
|
*/
|
||||||
|
Metamaps.TopicCard = {
|
||||||
|
openTopicCard: null, // stores the topic that's currently open
|
||||||
|
authorizedToEdit: false, // stores boolean for edit permission for open topic card
|
||||||
|
init: function () {
|
||||||
|
var self = Metamaps.TopicCard
|
||||||
|
|
||||||
|
// initialize best_in_place editing
|
||||||
|
$('.authenticated div.permission.canEdit .best_in_place').best_in_place()
|
||||||
|
|
||||||
|
Metamaps.TopicCard.generateShowcardHTML = Hogan.compile($('#topicCardTemplate').html())
|
||||||
|
|
||||||
|
// initialize topic card draggability and resizability
|
||||||
|
$('.showcard').draggable({
|
||||||
|
handle: '.metacodeImage'
|
||||||
|
})
|
||||||
|
|
||||||
|
embedly('on', 'card.rendered', self.embedlyCardRendered)
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Will open the Topic Card for the node that it's passed
|
||||||
|
* @param {$jit.Graph.Node} node
|
||||||
|
*/
|
||||||
|
showCard: function (node) {
|
||||||
|
var self = Metamaps.TopicCard
|
||||||
|
|
||||||
|
var topic = node.getData('topic')
|
||||||
|
|
||||||
|
self.openTopicCard = topic
|
||||||
|
self.authorizedToEdit = topic.authorizeToEdit(Metamaps.Active.Mapper)
|
||||||
|
// populate the card that's about to show with the right topics data
|
||||||
|
self.populateShowCard(topic)
|
||||||
|
$('.showcard').fadeIn('fast')
|
||||||
|
},
|
||||||
|
hideCard: function () {
|
||||||
|
var self = Metamaps.TopicCard
|
||||||
|
|
||||||
|
$('.showcard').fadeOut('fast')
|
||||||
|
self.openTopicCard = null
|
||||||
|
self.authorizedToEdit = false
|
||||||
|
},
|
||||||
|
embedlyCardRendered: function (iframe) {
|
||||||
|
var self = Metamaps.TopicCard
|
||||||
|
|
||||||
|
$('#embedlyLinkLoader').hide()
|
||||||
|
|
||||||
|
// means that the embedly call returned 404 not found
|
||||||
|
if ($('#embedlyLink')[0]) {
|
||||||
|
$('#embedlyLink').css('display', 'block').fadeIn('fast')
|
||||||
|
$('.embeds').addClass('nonEmbedlyLink')
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.CardOnGraph').addClass('hasAttachment')
|
||||||
|
if (self.authorizedToEdit) {
|
||||||
|
$('.embeds').append('<div id="linkremove"></div>')
|
||||||
|
$('#linkremove').click(self.removeLink)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
removeLink: function () {
|
||||||
|
var self = Metamaps.TopicCard
|
||||||
|
self.openTopicCard.save({
|
||||||
|
link: null
|
||||||
|
})
|
||||||
|
$('.embeds').empty().removeClass('nonEmbedlyLink')
|
||||||
|
$('#addLinkInput input').val('')
|
||||||
|
$('.attachments').removeClass('hidden')
|
||||||
|
$('.CardOnGraph').removeClass('hasAttachment')
|
||||||
|
},
|
||||||
|
bindShowCardListeners: function (topic) {
|
||||||
|
var self = Metamaps.TopicCard
|
||||||
|
var showCard = document.getElementById('showcard')
|
||||||
|
|
||||||
|
var authorized = self.authorizedToEdit
|
||||||
|
|
||||||
|
// get mapper image
|
||||||
|
var setMapperImage = function (mapper) {
|
||||||
|
$('.contributorIcon').attr('src', mapper.get('image'))
|
||||||
|
}
|
||||||
|
Metamaps.Mapper.get(topic.get('user_id'), setMapperImage)
|
||||||
|
|
||||||
|
// starting embed.ly
|
||||||
|
var resetFunc = function () {
|
||||||
|
$('#addLinkInput input').val('')
|
||||||
|
$('#addLinkInput input').focus()
|
||||||
|
}
|
||||||
|
var inputEmbedFunc = function (event) {
|
||||||
|
var element = this
|
||||||
|
setTimeout(function () {
|
||||||
|
var text = $(element).val()
|
||||||
|
if (event.type == 'paste' || (event.type == 'keyup' && event.which == 13)) {
|
||||||
|
// TODO evaluate converting this to '//' no matter what (infer protocol)
|
||||||
|
if (text.slice(0, 7) !== 'http://' &&
|
||||||
|
text.slice(0, 8) !== 'https://' &&
|
||||||
|
text.slice(0, 2) !== '//') {
|
||||||
|
text = '//' + text
|
||||||
|
}
|
||||||
|
topic.save({
|
||||||
|
link: text
|
||||||
|
})
|
||||||
|
var embedlyEl = $('<a/>', {
|
||||||
|
id: 'embedlyLink',
|
||||||
|
'data-card-description': '0',
|
||||||
|
href: text
|
||||||
|
}).html(text)
|
||||||
|
$('.attachments').addClass('hidden')
|
||||||
|
$('.embeds').append(embedlyEl)
|
||||||
|
$('.embeds').append('<div id="embedlyLinkLoader"></div>')
|
||||||
|
var loader = new CanvasLoader('embedlyLinkLoader')
|
||||||
|
loader.setColor('#4fb5c0'); // default is '#000000'
|
||||||
|
loader.setDiameter(28) // default is 40
|
||||||
|
loader.setDensity(41) // default is 40
|
||||||
|
loader.setRange(0.9); // default is 1.3
|
||||||
|
loader.show() // Hidden by default
|
||||||
|
var e = embedly('card', document.getElementById('embedlyLink'))
|
||||||
|
if (!e) {
|
||||||
|
self.handleInvalidLink()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 100)
|
||||||
|
}
|
||||||
|
$('#addLinkReset').click(resetFunc)
|
||||||
|
$('#addLinkInput input').bind('paste keyup', inputEmbedFunc)
|
||||||
|
|
||||||
|
// initialize the link card, if there is a link
|
||||||
|
if (topic.get('link') && topic.get('link') !== '') {
|
||||||
|
var loader = new CanvasLoader('embedlyLinkLoader')
|
||||||
|
loader.setColor('#4fb5c0'); // default is '#000000'
|
||||||
|
loader.setDiameter(28) // default is 40
|
||||||
|
loader.setDensity(41) // default is 40
|
||||||
|
loader.setRange(0.9); // default is 1.3
|
||||||
|
loader.show() // Hidden by default
|
||||||
|
var e = embedly('card', document.getElementById('embedlyLink'))
|
||||||
|
if (!e) {
|
||||||
|
self.handleInvalidLink()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var selectingMetacode = false
|
||||||
|
// attach the listener that shows the metacode title when you hover over the image
|
||||||
|
$('.showcard .metacodeImage').mouseenter(function () {
|
||||||
|
$('.showcard .icon').css('z-index', '4')
|
||||||
|
$('.showcard .metacodeTitle').show()
|
||||||
|
})
|
||||||
|
$('.showcard .linkItem.icon').mouseleave(function () {
|
||||||
|
if (!selectingMetacode) {
|
||||||
|
$('.showcard .metacodeTitle').hide()
|
||||||
|
$('.showcard .icon').css('z-index', '1')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
var metacodeLiClick = function () {
|
||||||
|
selectingMetacode = false
|
||||||
|
var metacodeId = parseInt($(this).attr('data-id'))
|
||||||
|
var metacode = Metamaps.Metacodes.get(metacodeId)
|
||||||
|
$('.CardOnGraph').find('.metacodeTitle').html(metacode.get('name'))
|
||||||
|
.append('<div class="expandMetacodeSelect"></div>')
|
||||||
|
.attr('class', 'metacodeTitle mbg' + metacode.id)
|
||||||
|
$('.CardOnGraph').find('.metacodeImage').css('background-image', 'url(' + metacode.get('icon') + ')')
|
||||||
|
topic.save({
|
||||||
|
metacode_id: metacode.id
|
||||||
|
})
|
||||||
|
Metamaps.Visualize.mGraph.plot()
|
||||||
|
$('.metacodeSelect').hide().removeClass('onRightEdge onBottomEdge')
|
||||||
|
$('.metacodeTitle').hide()
|
||||||
|
$('.showcard .icon').css('z-index', '1')
|
||||||
|
}
|
||||||
|
|
||||||
|
var openMetacodeSelect = function (event) {
|
||||||
|
var windowWidth
|
||||||
|
var showcardLeft
|
||||||
|
var TOPICCARD_WIDTH = 300
|
||||||
|
var METACODESELECT_WIDTH = 404
|
||||||
|
var distanceFromEdge
|
||||||
|
|
||||||
|
var MAX_METACODELIST_HEIGHT = 270
|
||||||
|
var windowHeight
|
||||||
|
var showcardTop
|
||||||
|
var topicTitleHeight
|
||||||
|
var distanceFromBottom
|
||||||
|
|
||||||
|
if (!selectingMetacode) {
|
||||||
|
selectingMetacode = true
|
||||||
|
|
||||||
|
// this is to make sure the metacode
|
||||||
|
// select is accessible onscreen, when opened
|
||||||
|
// while topic card is close to the right
|
||||||
|
// edge of the screen
|
||||||
|
windowWidth = $(window).width()
|
||||||
|
showcardLeft = parseInt($('.showcard').css('left'))
|
||||||
|
distanceFromEdge = windowWidth - (showcardLeft + TOPICCARD_WIDTH)
|
||||||
|
if (distanceFromEdge < METACODESELECT_WIDTH) {
|
||||||
|
$('.metacodeSelect').addClass('onRightEdge')
|
||||||
|
}
|
||||||
|
|
||||||
|
// this is to make sure the metacode
|
||||||
|
// select is accessible onscreen, when opened
|
||||||
|
// while topic card is close to the bottom
|
||||||
|
// edge of the screen
|
||||||
|
windowHeight = $(window).height()
|
||||||
|
showcardTop = parseInt($('.showcard').css('top'))
|
||||||
|
topicTitleHeight = $('.showcard .title').height() + parseInt($('.showcard .title').css('padding-top')) + parseInt($('.showcard .title').css('padding-bottom'))
|
||||||
|
heightOfSetList = $('.showcard .metacodeSelect').height()
|
||||||
|
distanceFromBottom = windowHeight - (showcardTop + topicTitleHeight)
|
||||||
|
if (distanceFromBottom < MAX_METACODELIST_HEIGHT) {
|
||||||
|
$('.metacodeSelect').addClass('onBottomEdge')
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.metacodeSelect').show()
|
||||||
|
event.stopPropagation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var hideMetacodeSelect = function () {
|
||||||
|
selectingMetacode = false
|
||||||
|
$('.metacodeSelect').hide().removeClass('onRightEdge onBottomEdge')
|
||||||
|
$('.metacodeTitle').hide()
|
||||||
|
$('.showcard .icon').css('z-index', '1')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (authorized) {
|
||||||
|
$('.showcard .metacodeTitle').click(openMetacodeSelect)
|
||||||
|
$('.showcard').click(hideMetacodeSelect)
|
||||||
|
$('.metacodeSelect > ul > li').click(function (event) {
|
||||||
|
event.stopPropagation()
|
||||||
|
})
|
||||||
|
$('.metacodeSelect li li').click(metacodeLiClick)
|
||||||
|
|
||||||
|
var bipName = $(showCard).find('.best_in_place_name')
|
||||||
|
bipName.bind('best_in_place:activate', function () {
|
||||||
|
var $el = bipName.find('textarea')
|
||||||
|
var el = $el[0]
|
||||||
|
|
||||||
|
$el.attr('maxlength', '140')
|
||||||
|
|
||||||
|
$('.showcard .title').append('<div class="nameCounter forTopic"></div>')
|
||||||
|
|
||||||
|
var callback = function (data) {
|
||||||
|
$('.nameCounter.forTopic').html(data.all + '/140')
|
||||||
|
}
|
||||||
|
Countable.live(el, callback)
|
||||||
|
})
|
||||||
|
bipName.bind('best_in_place:deactivate', function () {
|
||||||
|
$('.nameCounter.forTopic').remove()
|
||||||
|
})
|
||||||
|
|
||||||
|
// bind best_in_place ajax callbacks
|
||||||
|
bipName.bind('ajax:success', function () {
|
||||||
|
var name = Metamaps.Util.decodeEntities($(this).html())
|
||||||
|
topic.set('name', name)
|
||||||
|
topic.trigger('saved')
|
||||||
|
})
|
||||||
|
|
||||||
|
$(showCard).find('.best_in_place_desc').bind('ajax:success', function () {
|
||||||
|
this.innerHTML = this.innerHTML.replace(/\r/g, '')
|
||||||
|
var desc = $(this).html() === $(this).data('nil') ? '' : $(this).html()
|
||||||
|
topic.set('desc', desc)
|
||||||
|
topic.trigger('saved')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var permissionLiClick = function (event) {
|
||||||
|
selectingPermission = false
|
||||||
|
var permission = $(this).attr('class')
|
||||||
|
topic.save({
|
||||||
|
permission: permission,
|
||||||
|
defer_to_map_id: null
|
||||||
|
})
|
||||||
|
$('.showcard .mapPerm').removeClass('co pu pr minimize').addClass(permission.substring(0, 2))
|
||||||
|
$('.showcard .permissionSelect').remove()
|
||||||
|
event.stopPropagation()
|
||||||
|
}
|
||||||
|
|
||||||
|
var openPermissionSelect = function (event) {
|
||||||
|
if (!selectingPermission) {
|
||||||
|
selectingPermission = true
|
||||||
|
$(this).addClass('minimize') // this line flips the drop down arrow to a pull up arrow
|
||||||
|
if ($(this).hasClass('co')) {
|
||||||
|
$(this).append('<ul class="permissionSelect"><li class="public"></li><li class="private"></li></ul>')
|
||||||
|
} else if ($(this).hasClass('pu')) {
|
||||||
|
$(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="private"></li></ul>')
|
||||||
|
} else if ($(this).hasClass('pr')) {
|
||||||
|
$(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="public"></li></ul>')
|
||||||
|
}
|
||||||
|
$('.showcard .permissionSelect li').click(permissionLiClick)
|
||||||
|
event.stopPropagation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var hidePermissionSelect = function () {
|
||||||
|
selectingPermission = false
|
||||||
|
$('.showcard .yourTopic .mapPerm').removeClass('minimize') // this line flips the pull up arrow to a drop down arrow
|
||||||
|
$('.showcard .permissionSelect').remove()
|
||||||
|
}
|
||||||
|
// ability to change permission
|
||||||
|
var selectingPermission = false
|
||||||
|
if (topic.authorizePermissionChange(Metamaps.Active.Mapper)) {
|
||||||
|
$('.showcard .yourTopic .mapPerm').click(openPermissionSelect)
|
||||||
|
$('.showcard').click(hidePermissionSelect)
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.links .mapCount').unbind().click(function (event) {
|
||||||
|
$('.mapCount .tip').toggle()
|
||||||
|
$('.showcard .hoverTip').toggleClass('hide')
|
||||||
|
event.stopPropagation()
|
||||||
|
})
|
||||||
|
$('.mapCount .tip').unbind().click(function (event) {
|
||||||
|
event.stopPropagation()
|
||||||
|
})
|
||||||
|
$('.showcard').unbind('.hideTip').bind('click.hideTip', function () {
|
||||||
|
$('.mapCount .tip').hide()
|
||||||
|
$('.showcard .hoverTip').removeClass('hide')
|
||||||
|
})
|
||||||
|
|
||||||
|
$('.mapCount .tip li a').click(Metamaps.Router.intercept)
|
||||||
|
|
||||||
|
var originalText = $('.showMore').html()
|
||||||
|
$('.mapCount .tip .showMore').unbind().toggle(
|
||||||
|
function (event) {
|
||||||
|
$('.extraText').toggleClass('hideExtra')
|
||||||
|
$('.showMore').html('Show less...')
|
||||||
|
},
|
||||||
|
function (event) {
|
||||||
|
$('.extraText').toggleClass('hideExtra')
|
||||||
|
$('.showMore').html(originalText)
|
||||||
|
})
|
||||||
|
|
||||||
|
$('.mapCount .tip showMore').unbind().click(function (event) {
|
||||||
|
event.stopPropagation()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
handleInvalidLink: function () {
|
||||||
|
var self = Metamaps.TopicCard
|
||||||
|
|
||||||
|
self.removeLink()
|
||||||
|
Metamaps.GlobalUI.notifyUser('Invalid link')
|
||||||
|
},
|
||||||
|
populateShowCard: function (topic) {
|
||||||
|
var self = Metamaps.TopicCard
|
||||||
|
|
||||||
|
var showCard = document.getElementById('showcard')
|
||||||
|
|
||||||
|
$(showCard).find('.permission').remove()
|
||||||
|
|
||||||
|
var topicForTemplate = self.buildObject(topic)
|
||||||
|
var html = self.generateShowcardHTML.render(topicForTemplate)
|
||||||
|
|
||||||
|
if (topic.authorizeToEdit(Metamaps.Active.Mapper)) {
|
||||||
|
var perm = document.createElement('div')
|
||||||
|
|
||||||
|
var string = 'permission canEdit'
|
||||||
|
if (topic.authorizePermissionChange(Metamaps.Active.Mapper)) string += ' yourTopic'
|
||||||
|
perm.className = string
|
||||||
|
perm.innerHTML = html
|
||||||
|
showCard.appendChild(perm)
|
||||||
|
} else {
|
||||||
|
var perm = document.createElement('div')
|
||||||
|
perm.className = 'permission cannotEdit'
|
||||||
|
perm.innerHTML = html
|
||||||
|
showCard.appendChild(perm)
|
||||||
|
}
|
||||||
|
|
||||||
|
Metamaps.TopicCard.bindShowCardListeners(topic)
|
||||||
|
},
|
||||||
|
generateShowcardHTML: null, // will be initialized into a Hogan template within init function
|
||||||
|
// generateShowcardHTML
|
||||||
|
buildObject: function (topic) {
|
||||||
|
var self = Metamaps.TopicCard
|
||||||
|
|
||||||
|
var nodeValues = {}
|
||||||
|
|
||||||
|
var authorized = topic.authorizeToEdit(Metamaps.Active.Mapper)
|
||||||
|
|
||||||
|
if (!authorized) {
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
|
||||||
|
var desc_nil = 'Click to add description...'
|
||||||
|
|
||||||
|
nodeValues.attachmentsHidden = ''
|
||||||
|
if (topic.get('link') && topic.get('link') !== '') {
|
||||||
|
nodeValues.embeds = '<a href="' + topic.get('link') + '" id="embedlyLink" target="_blank" data-card-description="0">'
|
||||||
|
nodeValues.embeds += topic.get('link')
|
||||||
|
nodeValues.embeds += '</a><div id="embedlyLinkLoader"></div>'
|
||||||
|
nodeValues.attachmentsHidden = 'hidden'
|
||||||
|
nodeValues.hasAttachment = 'hasAttachment'
|
||||||
|
} else {
|
||||||
|
nodeValues.embeds = ''
|
||||||
|
nodeValues.hasAttachment = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
if (authorized) {
|
||||||
|
nodeValues.attachments = '<div class="addLink"><div id="addLinkIcon"></div>'
|
||||||
|
nodeValues.attachments += '<div id="addLinkInput"><input placeholder="Enter or paste a link"></input>'
|
||||||
|
nodeValues.attachments += '<div id="addLinkReset"></div></div></div>'
|
||||||
|
} else {
|
||||||
|
nodeValues.attachmentsHidden = 'hidden'
|
||||||
|
nodeValues.attachments = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
var inmapsAr = topic.get('inmaps')
|
||||||
|
var inmapsLinks = topic.get('inmapsLinks')
|
||||||
|
nodeValues.inmaps = ''
|
||||||
|
if (inmapsAr.length < 6) {
|
||||||
|
for (i = 0; i < inmapsAr.length; i++) {
|
||||||
|
var url = '/maps/' + inmapsLinks[i]
|
||||||
|
nodeValues.inmaps += '<li><a href="' + url + '">' + inmapsAr[i] + '</a></li>'
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (i = 0; i < 5; i++) {
|
||||||
|
var url = '/maps/' + inmapsLinks[i]
|
||||||
|
nodeValues.inmaps += '<li><a href="' + url + '">' + inmapsAr[i] + '</a></li>'
|
||||||
|
}
|
||||||
|
extra = inmapsAr.length - 5
|
||||||
|
nodeValues.inmaps += '<li><span class="showMore">See ' + extra + ' more...</span></li>'
|
||||||
|
for (i = 5; i < inmapsAr.length; i++) {
|
||||||
|
var url = '/maps/' + inmapsLinks[i]
|
||||||
|
nodeValues.inmaps += '<li class="hideExtra extraText"><a href="' + url + '">' + inmapsAr[i] + '</a></li>'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nodeValues.permission = topic.get('calculated_permission')
|
||||||
|
nodeValues.mk_permission = topic.get('calculated_permission').substring(0, 2)
|
||||||
|
nodeValues.map_count = topic.get('map_count').toString()
|
||||||
|
nodeValues.synapse_count = topic.get('synapse_count').toString()
|
||||||
|
nodeValues.id = topic.isNew() ? topic.cid : topic.id
|
||||||
|
nodeValues.metacode = topic.getMetacode().get('name')
|
||||||
|
nodeValues.metacode_class = 'mbg' + topic.get('metacode_id')
|
||||||
|
nodeValues.imgsrc = topic.getMetacode().get('icon')
|
||||||
|
nodeValues.name = topic.get('name')
|
||||||
|
nodeValues.userid = topic.get('user_id')
|
||||||
|
nodeValues.username = topic.get('user_name')
|
||||||
|
nodeValues.date = topic.getDate()
|
||||||
|
// the code for this is stored in /views/main/_metacodeOptions.html.erb
|
||||||
|
nodeValues.metacode_select = $('#metacodeOptions').html()
|
||||||
|
nodeValues.desc_nil = desc_nil
|
||||||
|
nodeValues.desc = (topic.get('desc') == '' && authorized) ? desc_nil : topic.get('desc')
|
||||||
|
return nodeValues
|
||||||
|
}
|
||||||
|
}; // end Metamaps.TopicCard
|
130
app/assets/javascripts/src/Metamaps.Util.js
Normal file
130
app/assets/javascripts/src/Metamaps.Util.js
Normal file
|
@ -0,0 +1,130 @@
|
||||||
|
/* global Metamaps */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Metamaps.Util.js
|
||||||
|
*
|
||||||
|
* Dependencies:
|
||||||
|
* - Metamaps.Visualize
|
||||||
|
*/
|
||||||
|
|
||||||
|
Metamaps.Util = {
|
||||||
|
// helper function to determine how many lines are needed
|
||||||
|
// Line Splitter Function
|
||||||
|
// copyright Stephen Chapman, 19th April 2006
|
||||||
|
// you may copy this code but please keep the copyright notice as well
|
||||||
|
splitLine: function (st, n) {
|
||||||
|
var b = ''
|
||||||
|
var s = st ? st : ''
|
||||||
|
while (s.length > n) {
|
||||||
|
var c = s.substring(0, n)
|
||||||
|
var d = c.lastIndexOf(' ')
|
||||||
|
var e = c.lastIndexOf('\n')
|
||||||
|
if (e != -1) d = e
|
||||||
|
if (d == -1) d = n
|
||||||
|
b += c.substring(0, d) + '\n'
|
||||||
|
s = s.substring(d + 1)
|
||||||
|
}
|
||||||
|
return b + s
|
||||||
|
},
|
||||||
|
nowDateFormatted: function () {
|
||||||
|
var date = new Date(Date.now())
|
||||||
|
var month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)
|
||||||
|
var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
|
||||||
|
var year = date.getFullYear()
|
||||||
|
|
||||||
|
return month + '/' + day + '/' + year
|
||||||
|
},
|
||||||
|
decodeEntities: function (desc) {
|
||||||
|
var str, temp = document.createElement('p')
|
||||||
|
temp.innerHTML = desc // browser handles the topics
|
||||||
|
str = temp.textContent || temp.innerText
|
||||||
|
temp = null // delete the element
|
||||||
|
return str
|
||||||
|
}, // decodeEntities
|
||||||
|
getDistance: function (p1, p2) {
|
||||||
|
return Math.sqrt(Math.pow((p2.x - p1.x), 2) + Math.pow((p2.y - p1.y), 2))
|
||||||
|
},
|
||||||
|
coordsToPixels: function (coords) {
|
||||||
|
if (Metamaps.Visualize.mGraph) {
|
||||||
|
var canvas = Metamaps.Visualize.mGraph.canvas,
|
||||||
|
s = canvas.getSize(),
|
||||||
|
p = canvas.getPos(),
|
||||||
|
ox = canvas.translateOffsetX,
|
||||||
|
oy = canvas.translateOffsetY,
|
||||||
|
sx = canvas.scaleOffsetX,
|
||||||
|
sy = canvas.scaleOffsetY
|
||||||
|
var pixels = {
|
||||||
|
x: (coords.x / (1 / sx)) + p.x + s.width / 2 + ox,
|
||||||
|
y: (coords.y / (1 / sy)) + p.y + s.height / 2 + oy
|
||||||
|
}
|
||||||
|
return pixels
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
x: 0,
|
||||||
|
y: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
pixelsToCoords: function (pixels) {
|
||||||
|
var coords
|
||||||
|
if (Metamaps.Visualize.mGraph) {
|
||||||
|
var canvas = Metamaps.Visualize.mGraph.canvas,
|
||||||
|
s = canvas.getSize(),
|
||||||
|
p = canvas.getPos(),
|
||||||
|
ox = canvas.translateOffsetX,
|
||||||
|
oy = canvas.translateOffsetY,
|
||||||
|
sx = canvas.scaleOffsetX,
|
||||||
|
sy = canvas.scaleOffsetY
|
||||||
|
coords = {
|
||||||
|
x: (pixels.x - p.x - s.width / 2 - ox) * (1 / sx),
|
||||||
|
y: (pixels.y - p.y - s.height / 2 - oy) * (1 / sy),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
coords = {
|
||||||
|
x: 0,
|
||||||
|
y: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return coords
|
||||||
|
},
|
||||||
|
getPastelColor: function () {
|
||||||
|
var r = (Math.round(Math.random() * 127) + 127).toString(16)
|
||||||
|
var g = (Math.round(Math.random() * 127) + 127).toString(16)
|
||||||
|
var b = (Math.round(Math.random() * 127) + 127).toString(16)
|
||||||
|
return Metamaps.Util.colorLuminance('#' + r + g + b, -0.4)
|
||||||
|
},
|
||||||
|
// darkens a hex value by 'lum' percentage
|
||||||
|
colorLuminance: function (hex, lum) {
|
||||||
|
// validate hex string
|
||||||
|
hex = String(hex).replace(/[^0-9a-f]/gi, '')
|
||||||
|
if (hex.length < 6) {
|
||||||
|
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]
|
||||||
|
}
|
||||||
|
lum = lum || 0
|
||||||
|
|
||||||
|
// convert to decimal and change luminosity
|
||||||
|
var rgb = '#', c, i
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
|
c = parseInt(hex.substr(i * 2, 2), 16)
|
||||||
|
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16)
|
||||||
|
rgb += ('00' + c).substr(c.length)
|
||||||
|
}
|
||||||
|
|
||||||
|
return rgb
|
||||||
|
},
|
||||||
|
generateOptionsList: function (data) {
|
||||||
|
var newlist = ''
|
||||||
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
newlist = newlist + '<option value="' + data[i]['id'] + '">' + data[i]['1'][1] + '</option>'
|
||||||
|
}
|
||||||
|
return newlist
|
||||||
|
},
|
||||||
|
checkURLisImage: function (url) {
|
||||||
|
// when the page reloads the following regular expression will be screwed up
|
||||||
|
// please replace it with this one before you save: /*backslashhere*.(jpeg|jpg|gif|png)$/
|
||||||
|
return (url.match(/\.(jpeg|jpg|gif|png)$/) != null)
|
||||||
|
},
|
||||||
|
checkURLisYoutubeVideo: function (url) {
|
||||||
|
return (url.match(/^https?:\/\/(?:www\.)?youtube.com\/watch\?(?=[^?]*v=\w+)(?:[^\s?]+)?$/) != null)
|
||||||
|
}
|
||||||
|
}; // end Metamaps.Util
|
210
app/assets/javascripts/src/Metamaps.Visualize.js
Normal file
210
app/assets/javascripts/src/Metamaps.Visualize.js
Normal file
|
@ -0,0 +1,210 @@
|
||||||
|
/* global Metamaps, $ */
|
||||||
|
/*
|
||||||
|
* Metamaps.Visualize
|
||||||
|
*
|
||||||
|
* Dependencies:
|
||||||
|
* - Metamaps.Active
|
||||||
|
* - Metamaps.JIT
|
||||||
|
* - Metamaps.Loading
|
||||||
|
* - Metamaps.Metacodes
|
||||||
|
* - Metamaps.Router
|
||||||
|
* - Metamaps.Synapses
|
||||||
|
* - Metamaps.TopicCard
|
||||||
|
* - Metamaps.Topics
|
||||||
|
* - Metamaps.Touch
|
||||||
|
* - Metamaps.Visualize
|
||||||
|
*/
|
||||||
|
|
||||||
|
Metamaps.Visualize = {
|
||||||
|
mGraph: null, // a reference to the graph object.
|
||||||
|
cameraPosition: null, // stores the camera position when using a 3D visualization
|
||||||
|
type: 'ForceDirected', // the type of graph we're building, could be "RGraph", "ForceDirected", or "ForceDirected3D"
|
||||||
|
loadLater: false, // indicates whether there is JSON that should be loaded right in the offset, or whether to wait till the first topic is created
|
||||||
|
init: function () {
|
||||||
|
var self = Metamaps.Visualize
|
||||||
|
// disable awkward dragging of the canvas element that would sometimes happen
|
||||||
|
$('#infovis-canvas').on('dragstart', function (event) {
|
||||||
|
event.preventDefault()
|
||||||
|
})
|
||||||
|
|
||||||
|
// prevent touch events on the canvas from default behaviour
|
||||||
|
$('#infovis-canvas').bind('touchstart', function (event) {
|
||||||
|
event.preventDefault()
|
||||||
|
self.mGraph.events.touched = true
|
||||||
|
})
|
||||||
|
|
||||||
|
// prevent touch events on the canvas from default behaviour
|
||||||
|
$('#infovis-canvas').bind('touchmove', function (event) {
|
||||||
|
// Metamaps.JIT.touchPanZoomHandler(event)
|
||||||
|
})
|
||||||
|
|
||||||
|
// prevent touch events on the canvas from default behaviour
|
||||||
|
$('#infovis-canvas').bind('touchend touchcancel', function (event) {
|
||||||
|
lastDist = 0
|
||||||
|
if (!self.mGraph.events.touchMoved && !Metamaps.Touch.touchDragNode) Metamaps.TopicCard.hideCurrentCard()
|
||||||
|
self.mGraph.events.touched = self.mGraph.events.touchMoved = false
|
||||||
|
Metamaps.Touch.touchDragNode = false
|
||||||
|
})
|
||||||
|
},
|
||||||
|
computePositions: function () {
|
||||||
|
var self = Metamaps.Visualize,
|
||||||
|
mapping
|
||||||
|
|
||||||
|
if (self.type == 'RGraph') {
|
||||||
|
var i, l, startPos, endPos, topic, synapse
|
||||||
|
|
||||||
|
self.mGraph.graph.eachNode(function (n) {
|
||||||
|
topic = Metamaps.Topics.get(n.id)
|
||||||
|
topic.set({ node: n }, { silent: true })
|
||||||
|
topic.updateNode()
|
||||||
|
|
||||||
|
n.eachAdjacency(function (edge) {
|
||||||
|
if (!edge.getData('init')) {
|
||||||
|
edge.setData('init', true)
|
||||||
|
|
||||||
|
l = edge.getData('synapseIDs').length
|
||||||
|
for (i = 0; i < l; i++) {
|
||||||
|
synapse = Metamaps.Synapses.get(edge.getData('synapseIDs')[i])
|
||||||
|
synapse.set({ edge: edge }, { silent: true })
|
||||||
|
synapse.updateEdge()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
var pos = n.getPos()
|
||||||
|
pos.setc(-200, -200)
|
||||||
|
})
|
||||||
|
self.mGraph.compute('end')
|
||||||
|
} else if (self.type == 'ForceDirected') {
|
||||||
|
var i, l, startPos, endPos, topic, synapse
|
||||||
|
|
||||||
|
self.mGraph.graph.eachNode(function (n) {
|
||||||
|
topic = Metamaps.Topics.get(n.id)
|
||||||
|
topic.set({ node: n }, { silent: true })
|
||||||
|
topic.updateNode()
|
||||||
|
mapping = topic.getMapping()
|
||||||
|
|
||||||
|
n.eachAdjacency(function (edge) {
|
||||||
|
if (!edge.getData('init')) {
|
||||||
|
edge.setData('init', true)
|
||||||
|
|
||||||
|
l = edge.getData('synapseIDs').length
|
||||||
|
for (i = 0; i < l; i++) {
|
||||||
|
synapse = Metamaps.Synapses.get(edge.getData('synapseIDs')[i])
|
||||||
|
synapse.set({ edge: edge }, { silent: true })
|
||||||
|
synapse.updateEdge()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
startPos = new $jit.Complex(0, 0)
|
||||||
|
endPos = new $jit.Complex(mapping.get('xloc'), mapping.get('yloc'))
|
||||||
|
n.setPos(startPos, 'start')
|
||||||
|
n.setPos(endPos, 'end')
|
||||||
|
})
|
||||||
|
} else if (self.type == 'ForceDirected3D') {
|
||||||
|
self.mGraph.compute()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* render does the heavy lifting of creating the engine that renders the graph with the properties we desire
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
render: function () {
|
||||||
|
var self = Metamaps.Visualize, RGraphSettings, FDSettings
|
||||||
|
|
||||||
|
if (self.type == 'RGraph' && (!self.mGraph || self.mGraph instanceof $jit.ForceDirected)) {
|
||||||
|
RGraphSettings = $.extend(true, {}, Metamaps.JIT.ForceDirected.graphSettings)
|
||||||
|
|
||||||
|
$jit.RGraph.Plot.NodeTypes.implement(Metamaps.JIT.ForceDirected.nodeSettings)
|
||||||
|
$jit.RGraph.Plot.EdgeTypes.implement(Metamaps.JIT.ForceDirected.edgeSettings)
|
||||||
|
|
||||||
|
RGraphSettings.width = $(document).width()
|
||||||
|
RGraphSettings.height = $(document).height()
|
||||||
|
RGraphSettings.background = Metamaps.JIT.RGraph.background
|
||||||
|
RGraphSettings.levelDistance = Metamaps.JIT.RGraph.levelDistance
|
||||||
|
|
||||||
|
self.mGraph = new $jit.RGraph(RGraphSettings)
|
||||||
|
} else if (self.type == 'ForceDirected' && (!self.mGraph || self.mGraph instanceof $jit.RGraph)) {
|
||||||
|
FDSettings = $.extend(true, {}, Metamaps.JIT.ForceDirected.graphSettings)
|
||||||
|
|
||||||
|
$jit.ForceDirected.Plot.NodeTypes.implement(Metamaps.JIT.ForceDirected.nodeSettings)
|
||||||
|
$jit.ForceDirected.Plot.EdgeTypes.implement(Metamaps.JIT.ForceDirected.edgeSettings)
|
||||||
|
|
||||||
|
FDSettings.width = $('body').width()
|
||||||
|
FDSettings.height = $('body').height()
|
||||||
|
|
||||||
|
self.mGraph = new $jit.ForceDirected(FDSettings)
|
||||||
|
} else if (self.type == 'ForceDirected3D' && !self.mGraph) {
|
||||||
|
// init ForceDirected3D
|
||||||
|
self.mGraph = new $jit.ForceDirected3D(Metamaps.JIT.ForceDirected3D.graphSettings)
|
||||||
|
self.cameraPosition = self.mGraph.canvas.canvases[0].camera.position
|
||||||
|
} else {
|
||||||
|
self.mGraph.graph.empty()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (self.type == 'ForceDirected' && Metamaps.Active.Mapper) $.post('/maps/' + Metamaps.Active.Map.id + '/events/user_presence')
|
||||||
|
|
||||||
|
function runAnimation () {
|
||||||
|
Metamaps.Loading.hide()
|
||||||
|
// load JSON data, if it's not empty
|
||||||
|
if (!self.loadLater) {
|
||||||
|
// load JSON data.
|
||||||
|
var rootIndex = 0
|
||||||
|
if (Metamaps.Active.Topic) {
|
||||||
|
var node = _.find(Metamaps.JIT.vizData, function (node) {
|
||||||
|
return node.id === Metamaps.Active.Topic.id
|
||||||
|
})
|
||||||
|
rootIndex = _.indexOf(Metamaps.JIT.vizData, node)
|
||||||
|
}
|
||||||
|
self.mGraph.loadJSON(Metamaps.JIT.vizData, rootIndex)
|
||||||
|
// compute positions and plot.
|
||||||
|
self.computePositions()
|
||||||
|
self.mGraph.busy = true
|
||||||
|
if (self.type == 'RGraph') {
|
||||||
|
self.mGraph.fx.animate(Metamaps.JIT.RGraph.animate)
|
||||||
|
} else if (self.type == 'ForceDirected') {
|
||||||
|
self.mGraph.animate(Metamaps.JIT.ForceDirected.animateSavedLayout)
|
||||||
|
} else if (self.type == 'ForceDirected3D') {
|
||||||
|
self.mGraph.animate(Metamaps.JIT.ForceDirected.animateFDLayout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// hold until all the needed metacode images are loaded
|
||||||
|
// hold for a maximum of 80 passes, or 4 seconds of waiting time
|
||||||
|
var tries = 0
|
||||||
|
function hold () {
|
||||||
|
var unique = _.uniq(Metamaps.Topics.models, function (metacode) { return metacode.get('metacode_id'); }),
|
||||||
|
requiredMetacodes = _.map(unique, function (metacode) { return metacode.get('metacode_id'); }),
|
||||||
|
loadedCount = 0
|
||||||
|
|
||||||
|
_.each(requiredMetacodes, function (metacode_id) {
|
||||||
|
var metacode = Metamaps.Metacodes.get(metacode_id),
|
||||||
|
img = metacode ? metacode.get('image') : false
|
||||||
|
|
||||||
|
if (img && (img.complete || (typeof img.naturalWidth !== 'undefined' && img.naturalWidth !== 0))) {
|
||||||
|
loadedCount += 1
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (loadedCount === requiredMetacodes.length || tries > 80) runAnimation()
|
||||||
|
else setTimeout(function () { tries++; hold() }, 50)
|
||||||
|
}
|
||||||
|
hold()
|
||||||
|
|
||||||
|
// update the url now that the map is ready
|
||||||
|
clearTimeout(Metamaps.Router.timeoutId)
|
||||||
|
Metamaps.Router.timeoutId = setTimeout(function () {
|
||||||
|
var m = Metamaps.Active.Map
|
||||||
|
var t = Metamaps.Active.Topic
|
||||||
|
|
||||||
|
if (m && window.location.pathname !== '/maps/' + m.id) {
|
||||||
|
Metamaps.Router.navigate('/maps/' + m.id)
|
||||||
|
}
|
||||||
|
else if (t && window.location.pathname !== '/topics/' + t.id) {
|
||||||
|
Metamaps.Router.navigate('/topics/' + t.id)
|
||||||
|
}
|
||||||
|
}, 800)
|
||||||
|
}
|
||||||
|
}; // end Metamaps.Visualize
|
File diff suppressed because it is too large
Load diff
15
app/assets/javascripts/src/check-canvas-support.js
Normal file
15
app/assets/javascripts/src/check-canvas-support.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
// TODO document this user agent function
|
||||||
|
var labelType, useGradients, nativeTextSupport, animate
|
||||||
|
;(function () {
|
||||||
|
var ua = navigator.userAgent,
|
||||||
|
iStuff = ua.match(/iPhone/i) || ua.match(/iPad/i),
|
||||||
|
typeOfCanvas = typeof HTMLCanvasElement,
|
||||||
|
nativeCanvasSupport = (typeOfCanvas == 'object' || typeOfCanvas == 'function'),
|
||||||
|
textSupport = nativeCanvasSupport && (typeof document.createElement('canvas').getContext('2d').fillText == 'function')
|
||||||
|
// I'm setting this based on the fact that ExCanvas provides text support for IE
|
||||||
|
// and that as of today iPhone/iPad current text support is lame
|
||||||
|
labelType = (!nativeCanvasSupport || (textSupport && !iStuff)) ? 'Native' : 'HTML'
|
||||||
|
nativeTextSupport = labelType == 'Native'
|
||||||
|
useGradients = nativeCanvasSupport
|
||||||
|
animate = !(iStuff || !nativeCanvasSupport)
|
||||||
|
})()
|
13
app/assets/javascripts/test/Metamaps.Import.spec.js
Normal file
13
app/assets/javascripts/test/Metamaps.Import.spec.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
var chai = require('chai')
|
||||||
|
var expect = chai.expect
|
||||||
|
|
||||||
|
Metamaps = {}
|
||||||
|
Metamaps.Import = require('../src/Metamaps.Import')
|
||||||
|
|
||||||
|
describe('Metamaps.Import.js', function() {
|
||||||
|
it('has a topic whitelist', function() {
|
||||||
|
expect(Metamaps.Import.topicWhitelist).to.deep.equal(
|
||||||
|
['id', 'name', 'metacode', 'x', 'y', 'description', 'link', 'permission']
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
|
@ -1569,6 +1569,11 @@ h3.filterBox {
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.commonsMap .mapContributors {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
.mapContributors {
|
.mapContributors {
|
||||||
position: relative;
|
position: relative;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
|
@ -1576,6 +1581,7 @@ h3.filterBox {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
width: 64px;
|
width: 64px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#mapContribs {
|
#mapContribs {
|
||||||
float: left;
|
float: left;
|
||||||
border: 2px solid #424242;
|
border: 2px solid #424242;
|
||||||
|
@ -1591,7 +1597,7 @@ h3.filterBox {
|
||||||
#mapContribs.multiple {
|
#mapContribs.multiple {
|
||||||
box-shadow: 1px 1px 0 0 #B5B5B5,3px 2px 0 0 #424242,4px 3px 0 0 #B5B5B5,5px 4px 0 0 #424242;
|
box-shadow: 1px 1px 0 0 #B5B5B5,3px 2px 0 0 #424242,4px 3px 0 0 #B5B5B5,5px 4px 0 0 #424242;
|
||||||
}
|
}
|
||||||
.mapContributors span {
|
.mapContributors span.count {
|
||||||
height: 20px;
|
height: 20px;
|
||||||
padding-top: 5px;
|
padding-top: 5px;
|
||||||
padding-left: 8px;
|
padding-left: 8px;
|
||||||
|
@ -1626,10 +1632,11 @@ h3.filterBox {
|
||||||
.mapContributors .tip {
|
.mapContributors .tip {
|
||||||
top: 45px;
|
top: 45px;
|
||||||
left: -10px;
|
left: -10px;
|
||||||
|
min-width: 200px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mapContributors .tip ul {
|
.mapContributors .tip ul {
|
||||||
max-height: 188px;
|
max-height: 144px;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1652,7 +1659,7 @@ h3.filterBox {
|
||||||
.mapContributors .tip li a {
|
.mapContributors .tip li a {
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
.mapContributors div:after {
|
.mapContributors div.tip:after {
|
||||||
content: '';
|
content: '';
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: -4px;
|
top: -4px;
|
||||||
|
@ -1672,6 +1679,90 @@ h3.filterBox {
|
||||||
border-radius: 14px;
|
border-radius: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mapContributors span.twitter-typeahead {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.collabSearchField {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.collabNameWrapper {
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.collabIconWrapper img.icon {
|
||||||
|
position: relative;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.collabIconWrapper {
|
||||||
|
position: relative;
|
||||||
|
float: left;
|
||||||
|
padding: 0 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mapContributors .collabName {
|
||||||
|
font-weight: normal;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 28px;
|
||||||
|
color: #424242;
|
||||||
|
padding: 0 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
span.removeCollaborator {
|
||||||
|
position: absolute;
|
||||||
|
top: 11px;
|
||||||
|
right: 8px;
|
||||||
|
height: 16px;
|
||||||
|
width: 16px;
|
||||||
|
background-image: url(<%= asset_data_uri('removecollab_sprite.png') %>);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
span.removeCollaborator:hover {
|
||||||
|
background-position: -16px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
span.addCollab {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
background-image: url(<%= asset_data_uri('addcollab_sprite.png') %>);
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: middle;
|
||||||
|
margin: 0 12px 0 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input.collaboratorSearchField {
|
||||||
|
background: #FFFFFF;
|
||||||
|
height: 14px;
|
||||||
|
margin: 0;
|
||||||
|
padding: 10px 6px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 2px;
|
||||||
|
outline: none;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 14px;
|
||||||
|
color: #424242;
|
||||||
|
font-family: 'din-medium', helvetica, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tt-dataset.tt-dataset-collaborators {
|
||||||
|
padding: 2px;
|
||||||
|
background: #E0E0E0;
|
||||||
|
min-width: 156px;
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tt-dataset.tt-dataset .collabResult {
|
||||||
|
padding: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.collabResult.tt-suggestion.tt-cursor, .collabResult.tt-suggestion:hover {
|
||||||
|
background-color: #CCCCCC;
|
||||||
|
}
|
||||||
|
|
||||||
.mapInfoBox .mapPermission .tooltips {
|
.mapInfoBox .mapPermission .tooltips {
|
||||||
top: -20px;
|
top: -20px;
|
||||||
right: 36px;
|
right: 36px;
|
||||||
|
|
|
@ -681,6 +681,10 @@
|
||||||
background-image: url(<%= asset_data_uri 'exploremaps_sprite.png' %>);
|
background-image: url(<%= asset_data_uri 'exploremaps_sprite.png' %>);
|
||||||
background-position: 0 0;
|
background-position: 0 0;
|
||||||
}
|
}
|
||||||
|
.exploreMapsCenter .sharedMaps .exploreMapsIcon {
|
||||||
|
background-image: url(<%= asset_data_uri 'exploremaps_sprite.png' %>);
|
||||||
|
background-position: -96px 0;
|
||||||
|
}
|
||||||
.exploreMapsCenter .activeMaps .exploreMapsIcon {
|
.exploreMapsCenter .activeMaps .exploreMapsIcon {
|
||||||
background-image: url(<%= asset_data_uri 'exploremaps_sprite.png' %>);
|
background-image: url(<%= asset_data_uri 'exploremaps_sprite.png' %>);
|
||||||
background-position: -32px 0;
|
background-position: -32px 0;
|
||||||
|
@ -698,6 +702,9 @@
|
||||||
.featuredMaps:hover .exploreMapsIcon, .featuredMaps.active .exploreMapsIcon {
|
.featuredMaps:hover .exploreMapsIcon, .featuredMaps.active .exploreMapsIcon {
|
||||||
background-position: -64px -32px;
|
background-position: -64px -32px;
|
||||||
}
|
}
|
||||||
|
.sharedMaps:hover .exploreMapsIcon, .sharedMaps.active .exploreMapsIcon {
|
||||||
|
background-position: -96px -32px;
|
||||||
|
}
|
||||||
|
|
||||||
.mapsWrapper {
|
.mapsWrapper {
|
||||||
/*overflow-y: auto; */
|
/*overflow-y: auto; */
|
||||||
|
|
|
@ -32,7 +32,11 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_unauthorized
|
def handle_unauthorized
|
||||||
|
if authenticated?
|
||||||
head :forbidden # TODO make this better
|
head :forbidden # TODO make this better
|
||||||
|
else
|
||||||
|
redirect_to new_user_session_path, notice: "Try signing in to do that."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -4,7 +4,7 @@ class MainController < ApplicationController
|
||||||
include UsersHelper
|
include UsersHelper
|
||||||
include SynapsesHelper
|
include SynapsesHelper
|
||||||
|
|
||||||
after_action :verify_policy_scoped, except: :requestinvite
|
after_action :verify_policy_scoped, except: [:requestinvite, :searchmappers]
|
||||||
|
|
||||||
respond_to :html, :json
|
respond_to :html, :json
|
||||||
|
|
||||||
|
@ -133,8 +133,9 @@ class MainController < ApplicationController
|
||||||
#remove "mapper:" if appended at beginning
|
#remove "mapper:" if appended at beginning
|
||||||
term = term[7..-1] if term.downcase[0..6] == "mapper:"
|
term = term[7..-1] if term.downcase[0..6] == "mapper:"
|
||||||
search = term.downcase + '%'
|
search = term.downcase + '%'
|
||||||
builder = policy_scope(User) # TODO do I need to policy scope? I guess yes to verify_policy_scoped
|
|
||||||
builder = builder.where('LOWER("name") like ?', search)
|
skip_policy_scope # TODO builder = policy_scope(User)
|
||||||
|
builder = User.where('LOWER("name") like ?', search)
|
||||||
@mappers = builder.order(:name)
|
@mappers = builder.order(:name)
|
||||||
else
|
else
|
||||||
@mappers = []
|
@mappers = []
|
||||||
|
|
|
@ -45,6 +45,13 @@ class MappingsController < ApplicationController
|
||||||
@mapping = Mapping.find(params[:id])
|
@mapping = Mapping.find(params[:id])
|
||||||
authorize @mapping
|
authorize @mapping
|
||||||
|
|
||||||
|
mappable = @mapping.mappable
|
||||||
|
if mappable.defer_to_map
|
||||||
|
mappable.permission = mappable.defer_to_map.permission
|
||||||
|
mappable.defer_to_map_id = nil
|
||||||
|
mappable.save
|
||||||
|
end
|
||||||
|
|
||||||
@mapping.destroy
|
@mapping.destroy
|
||||||
|
|
||||||
head :no_content
|
head :no_content
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
class MapsController < ApplicationController
|
class MapsController < ApplicationController
|
||||||
|
before_action :require_user, only: [:create, :update, :access, :screenshot, :events, :destroy]
|
||||||
before_action :require_user, only: [:create, :update, :screenshot, :events, :destroy]
|
after_action :verify_authorized, except: [:activemaps, :featuredmaps, :mymaps, :sharedmaps, :usermaps, :events]
|
||||||
after_action :verify_authorized, except: [:activemaps, :featuredmaps, :mymaps, :usermaps, :events]
|
after_action :verify_policy_scoped, only: [:activemaps, :featuredmaps, :mymaps, :sharedmaps, :usermaps]
|
||||||
after_action :verify_policy_scoped, only: [:activemaps, :featuredmaps, :mymaps, :usermaps]
|
|
||||||
|
|
||||||
respond_to :html, :json, :csv
|
respond_to :html, :json, :csv
|
||||||
|
|
||||||
|
@ -53,6 +52,21 @@ class MapsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# GET /explore/shared
|
||||||
|
def sharedmaps
|
||||||
|
return redirect_to activemaps_url if !authenticated?
|
||||||
|
|
||||||
|
page = params[:page].present? ? params[:page] : 1
|
||||||
|
@maps = policy_scope(
|
||||||
|
Map.where("maps.id IN (?)", current_user.shared_maps.map(&:id))
|
||||||
|
).order("updated_at DESC").page(page).per(20)
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { respond_with(@maps, @user) }
|
||||||
|
format.json { render json: @maps }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# GET /explore/mapper/:id
|
# GET /explore/mapper/:id
|
||||||
def usermaps
|
def usermaps
|
||||||
page = params[:page].present? ? params[:page] : 1
|
page = params[:page].present? ? params[:page] : 1
|
||||||
|
@ -74,15 +88,13 @@ class MapsController < ApplicationController
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {
|
format.html {
|
||||||
@allmappers = @map.contributors
|
@allmappers = @map.contributors
|
||||||
@alltopics = @map.topics.to_a.delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && current_user.id != t.user_id)) }
|
@allcollaborators = @map.editors
|
||||||
@allsynapses = @map.synapses.to_a.delete_if {|s| s.permission == "private" && (!authenticated? || (authenticated? && current_user.id != s.user_id)) }
|
@alltopics = @map.topics.to_a.delete_if {|t| not policy(t).show? }
|
||||||
@allmappings = @map.mappings.to_a.delete_if {|m|
|
@allsynapses = @map.synapses.to_a.delete_if {|s| not policy(s).show? }
|
||||||
object = m.mappable
|
@allmappings = @map.mappings.to_a.delete_if {|m| not policy(m).show? }
|
||||||
!object || (object.permission == "private" && (!authenticated? || (authenticated? && current_user.id != object.user_id)))
|
|
||||||
}
|
|
||||||
@allmessages = @map.messages.sort_by(&:created_at)
|
@allmessages = @map.messages.sort_by(&:created_at)
|
||||||
|
|
||||||
respond_with(@allmappers, @allmappings, @allsynapses, @alltopics, @allmessages, @map)
|
respond_with(@allmappers, @allcollaborators, @allmappings, @allsynapses, @alltopics, @allmessages, @map)
|
||||||
}
|
}
|
||||||
format.json { render json: @map }
|
format.json { render json: @map }
|
||||||
format.csv { redirect_to action: :export, format: :csv }
|
format.csv { redirect_to action: :export, format: :csv }
|
||||||
|
@ -111,6 +123,9 @@ class MapsController < ApplicationController
|
||||||
if params[:event] == 'conversation'
|
if params[:event] == 'conversation'
|
||||||
Events::ConversationStartedOnMap.publish!(map, current_user)
|
Events::ConversationStartedOnMap.publish!(map, current_user)
|
||||||
valid_event = true
|
valid_event = true
|
||||||
|
elsif params[:event] == 'user_presence'
|
||||||
|
Events::UserPresentOnMap.publish!(map, current_user)
|
||||||
|
valid_event = true
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
@ -127,12 +142,11 @@ class MapsController < ApplicationController
|
||||||
authorize @map
|
authorize @map
|
||||||
|
|
||||||
@allmappers = @map.contributors
|
@allmappers = @map.contributors
|
||||||
@alltopics = @map.topics.to_a.delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && current_user.id != t.user_id)) }
|
@allcollaborators = @map.editors
|
||||||
@allsynapses = @map.synapses.to_a.delete_if {|s| s.permission == "private" && (!authenticated? || (authenticated? && current_user.id != s.user_id)) }
|
@alltopics = @map.topics.to_a.delete_if {|t| not policy(t).show? }
|
||||||
@allmappings = @map.mappings.to_a.delete_if {|m|
|
@allsynapses = @map.synapses.to_a.delete_if {|s| not policy(s).show? }
|
||||||
object = m.mappable
|
@allmappings = @map.mappings.to_a.delete_if {|m| not policy(m).show? }
|
||||||
!object || (object.permission == "private" && (!authenticated? || (authenticated? && current_user.id != object.user_id)))
|
|
||||||
}
|
|
||||||
|
|
||||||
@json = Hash.new()
|
@json = Hash.new()
|
||||||
@json['map'] = @map
|
@json['map'] = @map
|
||||||
|
@ -140,6 +154,7 @@ class MapsController < ApplicationController
|
||||||
@json['synapses'] = @allsynapses
|
@json['synapses'] = @allsynapses
|
||||||
@json['mappings'] = @allmappings
|
@json['mappings'] = @allmappings
|
||||||
@json['mappers'] = @allmappers
|
@json['mappers'] = @allmappers
|
||||||
|
@json['collaborators'] = @allcollaborators
|
||||||
@json['messages'] = @map.messages.sort_by(&:created_at)
|
@json['messages'] = @map.messages.sort_by(&:created_at)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
@ -215,6 +230,36 @@ class MapsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# POST maps/:id/access
|
||||||
|
def access
|
||||||
|
@map = Map.find(params[:id])
|
||||||
|
authorize @map
|
||||||
|
userIds = params[:access] || []
|
||||||
|
added = userIds.select { |uid|
|
||||||
|
user = User.find(uid)
|
||||||
|
if user.nil? || (current_user && user == current_user)
|
||||||
|
false
|
||||||
|
else
|
||||||
|
not @map.collaborators.include?(user)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
removed = @map.collaborators.select { |user| not userIds.include?(user.id.to_s) }.map(&:id)
|
||||||
|
added.each { |uid|
|
||||||
|
um = UserMap.create({ user_id: uid.to_i, map_id: @map.id })
|
||||||
|
user = User.find(uid.to_i)
|
||||||
|
MapMailer.invite_to_edit_email(@map, current_user, user).deliver_later
|
||||||
|
}
|
||||||
|
removed.each { |uid|
|
||||||
|
@map.user_maps.select{ |um| um.user_id == uid }.each{ |um| um.destroy }
|
||||||
|
}
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.json do
|
||||||
|
render :json => { :message => "Successfully altered edit permissions" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# POST maps/:id/upload_screenshot
|
# POST maps/:id/upload_screenshot
|
||||||
def screenshot
|
def screenshot
|
||||||
@map = Map.find(params[:id])
|
@map = Map.find(params[:id])
|
||||||
|
|
|
@ -51,7 +51,7 @@ class SynapsesController < ApplicationController
|
||||||
def destroy
|
def destroy
|
||||||
@synapse = Synapse.find(params[:id])
|
@synapse = Synapse.find(params[:id])
|
||||||
authorize @synapse
|
authorize @synapse
|
||||||
@synapse.delete
|
@synapse.destroy
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json { head :no_content }
|
format.json { head :no_content }
|
||||||
|
|
|
@ -150,7 +150,7 @@ puts @allsynapses.length
|
||||||
@topic = Topic.find(params[:id])
|
@topic = Topic.find(params[:id])
|
||||||
authorize @topic
|
authorize @topic
|
||||||
|
|
||||||
@topic.delete
|
@topic.destroy
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json { head :no_content }
|
format.json { head :no_content }
|
||||||
end
|
end
|
||||||
|
@ -159,6 +159,6 @@ puts @allsynapses.length
|
||||||
private
|
private
|
||||||
|
|
||||||
def topic_params
|
def topic_params
|
||||||
params.require(:topic).permit(:id, :name, :desc, :link, :permission, :user_id, :metacode_id)
|
params.require(:topic).permit(:id, :name, :desc, :link, :permission, :user_id, :metacode_id, :defer_to_map_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
4
app/mailers/application_mailer.rb
Normal file
4
app/mailers/application_mailer.rb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
class ApplicationMailer < ActionMailer::Base
|
||||||
|
default from: "team@metamaps.cc"
|
||||||
|
layout 'mailer'
|
||||||
|
end
|
10
app/mailers/map_mailer.rb
Normal file
10
app/mailers/map_mailer.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
class MapMailer < ApplicationMailer
|
||||||
|
default from: "team@metamaps.cc"
|
||||||
|
|
||||||
|
def invite_to_edit_email(map, inviter, invitee)
|
||||||
|
@inviter = inviter
|
||||||
|
@map = map
|
||||||
|
subject = @map.name + ' - Invitation to edit'
|
||||||
|
mail(to: invitee.email, subject: subject)
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,5 +1,5 @@
|
||||||
class Event < ActiveRecord::Base
|
class Event < ActiveRecord::Base
|
||||||
KINDS = %w[conversation_started_on_map topic_added_to_map synapse_added_to_map]
|
KINDS = %w[user_present_on_map conversation_started_on_map topic_added_to_map synapse_added_to_map]
|
||||||
|
|
||||||
#has_many :notifications, dependent: :destroy
|
#has_many :notifications, dependent: :destroy
|
||||||
belongs_to :eventable, polymorphic: true
|
belongs_to :eventable, polymorphic: true
|
||||||
|
|
18
app/models/events/user_present_on_map.rb
Normal file
18
app/models/events/user_present_on_map.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
class Events::UserPresentOnMap < Event
|
||||||
|
#after_create :notify_users!
|
||||||
|
|
||||||
|
def self.publish!(map, user)
|
||||||
|
create!(kind: "user_present_on_map",
|
||||||
|
eventable: map,
|
||||||
|
map: map,
|
||||||
|
user: user)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
#def notify_users!
|
||||||
|
# unless comment_vote.user == comment_vote.comment_user
|
||||||
|
# notify!(comment_vote.comment_user)
|
||||||
|
# end
|
||||||
|
#end
|
||||||
|
end
|
|
@ -8,6 +8,9 @@ class Map < ActiveRecord::Base
|
||||||
has_many :synapses, through: :synapsemappings, source: :mappable, source_type: "Synapse"
|
has_many :synapses, through: :synapsemappings, source: :mappable, source_type: "Synapse"
|
||||||
has_many :messages, as: :resource, dependent: :destroy
|
has_many :messages, as: :resource, dependent: :destroy
|
||||||
|
|
||||||
|
has_many :user_maps, dependent: :destroy
|
||||||
|
has_many :collaborators, through: :user_maps, source: :user
|
||||||
|
|
||||||
has_many :webhooks, as: :hookable
|
has_many :webhooks, as: :hookable
|
||||||
has_many :events, -> { includes :user }, as: :eventable, dependent: :destroy
|
has_many :events, -> { includes :user }, as: :eventable, dependent: :destroy
|
||||||
|
|
||||||
|
@ -45,6 +48,10 @@ class Map < ActiveRecord::Base
|
||||||
return contributors
|
return contributors
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def editors
|
||||||
|
collaborators + [self.user]
|
||||||
|
end
|
||||||
|
|
||||||
def topic_count
|
def topic_count
|
||||||
topics.length
|
topics.length
|
||||||
end
|
end
|
||||||
|
@ -65,6 +72,10 @@ class Map < ActiveRecord::Base
|
||||||
contributors.length
|
contributors.length
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def collaborator_ids
|
||||||
|
collaborators.map(&:id)
|
||||||
|
end
|
||||||
|
|
||||||
def screenshot_url
|
def screenshot_url
|
||||||
screenshot.url(:thumb)
|
screenshot.url(:thumb)
|
||||||
end
|
end
|
||||||
|
@ -78,7 +89,7 @@ class Map < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def as_json(options={})
|
def as_json(options={})
|
||||||
json = super(:methods =>[:user_name, :user_image, :topic_count, :synapse_count, :contributor_count, :screenshot_url], :except => [:screenshot_content_type, :screenshot_file_size, :screenshot_file_name, :screenshot_updated_at])
|
json = super(:methods =>[:user_name, :user_image, :topic_count, :synapse_count, :contributor_count, :collaborator_ids, :screenshot_url], :except => [:screenshot_content_type, :screenshot_file_size, :screenshot_file_name, :screenshot_updated_at])
|
||||||
json[:created_at_clean] = created_at_str
|
json[:created_at_clean] = created_at_str
|
||||||
json[:updated_at_clean] = updated_at_str
|
json[:updated_at_clean] = updated_at_str
|
||||||
json
|
json
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class Synapse < ActiveRecord::Base
|
class Synapse < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
belongs_to :defer_to_map, :class_name => 'Map', :foreign_key => 'defer_to_map_id'
|
||||||
|
|
||||||
belongs_to :topic1, :class_name => "Topic", :foreign_key => "node1_id"
|
belongs_to :topic1, :class_name => "Topic", :foreign_key => "node1_id"
|
||||||
belongs_to :topic2, :class_name => "Topic", :foreign_key => "node2_id"
|
belongs_to :topic2, :class_name => "Topic", :foreign_key => "node2_id"
|
||||||
|
@ -32,9 +33,29 @@ class Synapse < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
# :nocov:
|
# :nocov:
|
||||||
|
|
||||||
|
# :nocov:
|
||||||
|
def collaborator_ids
|
||||||
|
if defer_to_map
|
||||||
|
defer_to_map.editors.select{|mapper| not mapper == self.user }.map(&:id)
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# :nocov:
|
||||||
|
|
||||||
|
# :nocov:
|
||||||
|
def calculated_permission
|
||||||
|
if defer_to_map
|
||||||
|
defer_to_map.permission
|
||||||
|
else
|
||||||
|
permission
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# :nocov:
|
||||||
|
|
||||||
# :nocov:
|
# :nocov:
|
||||||
def as_json(options={})
|
def as_json(options={})
|
||||||
super(:methods =>[:user_name, :user_image])
|
super(:methods =>[:user_name, :user_image, :calculated_permission, :collaborator_ids])
|
||||||
end
|
end
|
||||||
# :nocov:
|
# :nocov:
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ class Topic < ActiveRecord::Base
|
||||||
include TopicsHelper
|
include TopicsHelper
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
belongs_to :defer_to_map, :class_name => 'Map', :foreign_key => 'defer_to_map_id'
|
||||||
|
|
||||||
has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id', dependent: :destroy
|
has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id', dependent: :destroy
|
||||||
has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id', dependent: :destroy
|
has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id', dependent: :destroy
|
||||||
|
@ -11,6 +12,8 @@ class Topic < ActiveRecord::Base
|
||||||
has_many :mappings, as: :mappable, dependent: :destroy
|
has_many :mappings, as: :mappable, dependent: :destroy
|
||||||
has_many :maps, :through => :mappings
|
has_many :maps, :through => :mappings
|
||||||
|
|
||||||
|
belongs_to :metacode
|
||||||
|
|
||||||
validates :permission, presence: true
|
validates :permission, presence: true
|
||||||
validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) }
|
validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) }
|
||||||
|
|
||||||
|
@ -39,8 +42,6 @@ class Topic < ActiveRecord::Base
|
||||||
topics1 + topics2
|
topics1 + topics2
|
||||||
end
|
end
|
||||||
|
|
||||||
belongs_to :metacode
|
|
||||||
|
|
||||||
scope :relatives1, ->(topic_id = nil) {
|
scope :relatives1, ->(topic_id = nil) {
|
||||||
includes(:topics1)
|
includes(:topics1)
|
||||||
.where('synapses.node1_id = ?', topic_id)
|
.where('synapses.node1_id = ?', topic_id)
|
||||||
|
@ -77,8 +78,24 @@ class Topic < ActiveRecord::Base
|
||||||
maps.map(&:id)
|
maps.map(&:id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def calculated_permission
|
||||||
|
if defer_to_map
|
||||||
|
defer_to_map.permission
|
||||||
|
else
|
||||||
|
permission
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def as_json(options={})
|
def as_json(options={})
|
||||||
super(:methods =>[:user_name, :user_image, :map_count, :synapse_count, :inmaps, :inmapsLinks])
|
super(:methods =>[:user_name, :user_image, :map_count, :synapse_count, :inmaps, :inmapsLinks, :calculated_permission, :collaborator_ids])
|
||||||
|
end
|
||||||
|
|
||||||
|
def collaborator_ids
|
||||||
|
if defer_to_map
|
||||||
|
defer_to_map.editors.select{|mapper| not mapper == self.user }.map(&:id)
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO move to a decorator?
|
# TODO move to a decorator?
|
||||||
|
|
|
@ -7,6 +7,8 @@ class User < ActiveRecord::Base
|
||||||
has_many :maps
|
has_many :maps
|
||||||
has_many :mappings
|
has_many :mappings
|
||||||
has_many :tokens
|
has_many :tokens
|
||||||
|
has_many :user_maps, dependent: :destroy
|
||||||
|
has_many :shared_maps, through: :user_maps, source: :map
|
||||||
|
|
||||||
after_create :generate_code
|
after_create :generate_code
|
||||||
|
|
||||||
|
|
4
app/models/user_map.rb
Normal file
4
app/models/user_map.rb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
class UserMap < ActiveRecord::Base
|
||||||
|
belongs_to :map
|
||||||
|
belongs_to :user
|
||||||
|
end
|
27
app/models/webhooks/slack/user_present_on_map.rb
Normal file
27
app/models/webhooks/slack/user_present_on_map.rb
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
class Webhooks::Slack::UserPresentOnMap < Webhooks::Slack::Base
|
||||||
|
|
||||||
|
def text
|
||||||
|
"Mapper *#{event.user.name}* has joined the map *#{event.map.name}*. #{view_map_on_metamaps('Map with them')}"
|
||||||
|
end
|
||||||
|
# todo: it would be sweet if it sends it with the metacode as the icon_url
|
||||||
|
|
||||||
|
def attachment_fallback
|
||||||
|
"" #{}"*#{eventable.name}*\n#{eventable.description}\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
def attachment_title
|
||||||
|
"" #proposal_link(eventable)
|
||||||
|
end
|
||||||
|
|
||||||
|
def attachment_text
|
||||||
|
"" # "#{eventable.description}\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
def attachment_fields
|
||||||
|
[{
|
||||||
|
title: "nothing",
|
||||||
|
value: "nothing"
|
||||||
|
}] #[motion_vote_field]
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -4,7 +4,8 @@ class MapPolicy < ApplicationPolicy
|
||||||
visible = ['public', 'commons']
|
visible = ['public', 'commons']
|
||||||
permission = 'maps.permission IN (?)'
|
permission = 'maps.permission IN (?)'
|
||||||
if user
|
if user
|
||||||
scope.where(permission + ' OR maps.user_id = ?', visible, user.id)
|
shared_maps = user.shared_maps.map(&:id)
|
||||||
|
scope.where(permission + ' OR maps.id IN (?) OR maps.user_id = ?', visible, shared_maps, user.id)
|
||||||
else
|
else
|
||||||
scope.where(permission, visible)
|
scope.where(permission, visible)
|
||||||
end
|
end
|
||||||
|
@ -28,7 +29,7 @@ class MapPolicy < ApplicationPolicy
|
||||||
end
|
end
|
||||||
|
|
||||||
def show?
|
def show?
|
||||||
record.permission == 'commons' || record.permission == 'public' || record.user == user
|
record.permission == 'commons' || record.permission == 'public' || record.collaborators.include?(user) || record.user == user
|
||||||
end
|
end
|
||||||
|
|
||||||
def export?
|
def export?
|
||||||
|
@ -48,7 +49,12 @@ class MapPolicy < ApplicationPolicy
|
||||||
end
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
user.present? && (record.permission == 'commons' || record.user == user)
|
user.present? && (record.permission == 'commons' || record.collaborators.include?(user) || record.user == user)
|
||||||
|
end
|
||||||
|
|
||||||
|
def access?
|
||||||
|
# note that this is to edit access
|
||||||
|
user.present? && record.user == user
|
||||||
end
|
end
|
||||||
|
|
||||||
def screenshot?
|
def screenshot?
|
||||||
|
|
|
@ -4,7 +4,7 @@ class SynapsePolicy < ApplicationPolicy
|
||||||
visible = ['public', 'commons']
|
visible = ['public', 'commons']
|
||||||
permission = 'synapses.permission IN (?)'
|
permission = 'synapses.permission IN (?)'
|
||||||
if user
|
if user
|
||||||
scope.where(permission + ' OR synapses.user_id = ?', visible, user.id)
|
scope.where(permission + ' OR synapses.defer_to_map_id IN (?) OR synapses.user_id = ?', visible, user.shared_maps.map(&:id), user.id)
|
||||||
else
|
else
|
||||||
scope.where(permission, visible)
|
scope.where(permission, visible)
|
||||||
end
|
end
|
||||||
|
@ -17,14 +17,29 @@ class SynapsePolicy < ApplicationPolicy
|
||||||
end
|
end
|
||||||
|
|
||||||
def show?
|
def show?
|
||||||
|
if record.defer_to_map.present?
|
||||||
|
map_policy.show?
|
||||||
|
else
|
||||||
record.permission == 'commons' || record.permission == 'public' || record.user == user
|
record.permission == 'commons' || record.permission == 'public' || record.user == user
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
user.present? && (record.permission == 'commons' || record.user == user)
|
if not user.present?
|
||||||
|
false
|
||||||
|
elsif record.defer_to_map.present?
|
||||||
|
map_policy.update?
|
||||||
|
else
|
||||||
|
record.permission == 'commons' || record.user == user
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy?
|
def destroy?
|
||||||
record.user == user || admin_override
|
record.user == user || admin_override
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Helpers
|
||||||
|
def map_policy
|
||||||
|
@map_policy ||= Pundit.policy(user, record.defer_to_map)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@ class TopicPolicy < ApplicationPolicy
|
||||||
visible = ['public', 'commons']
|
visible = ['public', 'commons']
|
||||||
permission = 'topics.permission IN (?)'
|
permission = 'topics.permission IN (?)'
|
||||||
if user
|
if user
|
||||||
scope.where(permission + ' OR topics.user_id = ?', visible, user.id)
|
scope.where(permission + ' OR topics.defer_to_map_id IN (?) OR topics.user_id = ?', visible, user.shared_maps.map(&:id), user.id)
|
||||||
else
|
else
|
||||||
scope.where(permission, visible)
|
scope.where(permission, visible)
|
||||||
end
|
end
|
||||||
|
@ -16,11 +16,21 @@ class TopicPolicy < ApplicationPolicy
|
||||||
end
|
end
|
||||||
|
|
||||||
def show?
|
def show?
|
||||||
|
if record.defer_to_map.present?
|
||||||
|
map_policy.show?
|
||||||
|
else
|
||||||
record.permission == 'commons' || record.permission == 'public' || record.user == user
|
record.permission == 'commons' || record.permission == 'public' || record.user == user
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
user.present? && (record.permission == 'commons' || record.user == user)
|
if not user.present?
|
||||||
|
false
|
||||||
|
elsif record.defer_to_map.present?
|
||||||
|
map_policy.update?
|
||||||
|
else
|
||||||
|
record.permission == 'commons' || record.user == user
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy?
|
def destroy?
|
||||||
|
@ -42,4 +52,9 @@ class TopicPolicy < ApplicationPolicy
|
||||||
def relatives?
|
def relatives?
|
||||||
show?
|
show?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Helpers
|
||||||
|
def map_policy
|
||||||
|
@map_policy ||= Pundit.policy(user, record.defer_to_map)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,5 +12,6 @@ class NewMapSerializer < ActiveModel::Serializer
|
||||||
has_many :synapses, serializer: NewSynapseSerializer
|
has_many :synapses, serializer: NewSynapseSerializer
|
||||||
has_many :mappings, serializer: NewMappingSerializer
|
has_many :mappings, serializer: NewMappingSerializer
|
||||||
has_many :contributors, root: :users, serializer: NewUserSerializer
|
has_many :contributors, root: :users, serializer: NewUserSerializer
|
||||||
|
has_many :collaborators, root: :users, serializer: NewUserSerializer
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
<div class="permIcon" data-permission="commons">
|
<div class="permIcon" data-permission="commons">
|
||||||
<div id="newmap_co" class="mapCommonsIcon mapPermIcon selected">
|
<div id="newmap_co" class="mapCommonsIcon mapPermIcon selected">
|
||||||
<div class="tip">
|
<div class="tip">
|
||||||
Collaborate with other mappers on editing this map. Those without accounts can view this map.
|
Anyone with an account can edit this map. Anyone without an account can only view it.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h4>COMMONS</h4>
|
<h4>COMMONS</h4>
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
<div class="permIcon" data-permission="public">
|
<div class="permIcon" data-permission="public">
|
||||||
<div id="newmap_pu" class="mapPublicIcon mapPermIcon">
|
<div id="newmap_pu" class="mapPublicIcon mapPermIcon">
|
||||||
<div class="tip">
|
<div class="tip">
|
||||||
Anyone, with or without an account, can view this map but not edit anything.
|
Only people you allow can edit this map. Anyone can view it.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h4>PUBLIC</h4>
|
<h4>PUBLIC</h4>
|
||||||
|
@ -41,14 +41,14 @@
|
||||||
<div class="permIcon" data-permission="private">
|
<div class="permIcon" data-permission="private">
|
||||||
<div id="newmap_pr" class="mapPrivateIcon mapPermIcon">
|
<div id="newmap_pr" class="mapPrivateIcon mapPermIcon">
|
||||||
<div class="tip">
|
<div class="tip">
|
||||||
Only you can view or edit this map.
|
Only people you allow can edit this map. No one else can view it.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h4>PRIVATE</h4>
|
<h4>PRIVATE</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfloat"></div>
|
<div class="clearfloat"></div>
|
||||||
</div>
|
</div>
|
||||||
<p class="permText">Collaborate with other mappers on editing this map. Those without accounts can view this map.</p>
|
<p class="permText">Anyone with an account can edit this map. Anyone without an account can only view it.</p>
|
||||||
<div class="clearfloat"></div>
|
<div class="clearfloat"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<div class="infoStatIcon mapContributors hoverForTip">
|
<div class="infoStatIcon mapContributors hoverForTip">
|
||||||
<img id="mapContribs" class="{{contributors_class}}"
|
<img id="mapContribs" class="{{contributors_class}}"
|
||||||
width="25" height="25" src="{{contributor_image}}" />
|
width="25" height="25" src="{{contributor_image}}" />
|
||||||
<span>{{contributor_count}}</span>
|
<span class="count">{{contributor_count}}</span>
|
||||||
<div class="tip">{{{contributor_list}}}</div>
|
<div class="tip">{{{contributor_list}}}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="infoStatIcon mapTopics">
|
<div class="infoStatIcon mapTopics">
|
||||||
|
@ -181,6 +181,18 @@
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script type="text/template" id="collaboratorSearchTemplate">
|
||||||
|
<div class="collabResult">
|
||||||
|
<div class="collabIconWrapper">
|
||||||
|
<img class="icon" width="25" height="25" src="{{profile}}">
|
||||||
|
</div>
|
||||||
|
<div class="collabNameWrapper">
|
||||||
|
<p class="collabName">{{label}}</p>
|
||||||
|
</div>
|
||||||
|
<div class="clearfloat"></div>
|
||||||
|
</div>
|
||||||
|
</script>
|
||||||
|
|
||||||
<script type="text/template" id="synapseAutocompleteTemplate">
|
<script type="text/template" id="synapseAutocompleteTemplate">
|
||||||
<div class="result{{rtype}}">
|
<div class="result{{rtype}}">
|
||||||
<p class="autocompleteSection synapseDesc">{{label}}</p>
|
<p class="autocompleteSection synapseDesc">{{label}}</p>
|
||||||
|
|
5
app/views/layouts/mailer.html.erb
Normal file
5
app/views/layouts/mailer.html.erb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<%= yield %>
|
||||||
|
</body>
|
||||||
|
</html>
|
1
app/views/layouts/mailer.text.erb
Normal file
1
app/views/layouts/mailer.text.erb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<%= yield %>
|
22
app/views/map_mailer/invite_to_edit_email.html.erb
Normal file
22
app/views/map_mailer/invite_to_edit_email.html.erb
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
|
||||||
|
</head>
|
||||||
|
<body style="font-family: sans-serif; width: 100%; padding: 24px 16px 16px 16px; background-color: #f5f5f5; text-align: center;">
|
||||||
|
|
||||||
|
<div style="padding: 16px; background: white; text-align: left;">
|
||||||
|
<% button_style = "background-color:#4fc059;border-radius:2px;color:white;display:inline-block;font-family:Roboto,Arial,Helvetica,sans-serif;font-size:12px;font-weight:bold;min-height:29px;line-height:29px;min-width:54px;outline:0px;padding:0 8px;text-align:center;text-decoration:none" %>
|
||||||
|
|
||||||
|
<p><span style="font-weight: bold;"><%= @inviter.name %></span> has invited you to <span style="font-weight: bold">collaboratively edit</span> the following metamap:</p>
|
||||||
|
<p><%= link_to @map.name, map_url(@map), target: "_blank", style: "font-size: 18px; text-decoration: none; color: #4fc059;" %></p>
|
||||||
|
<% if @map.desc %>
|
||||||
|
<p style="font-size: 12px;"><%= @map.desc %></p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= link_to 'Open in Metamaps', map_url(@map), target: "_blank", style: button_style %>
|
||||||
|
|
||||||
|
<p style="font-size: 12px;">Make sense with Metamaps</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
7
app/views/map_mailer/invite_to_edit_email.text.erb
Normal file
7
app/views/map_mailer/invite_to_edit_email.text.erb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<%= @inviter.name %> has invited you to collaboratively edit the following metamap:
|
||||||
|
|
||||||
|
<%= @map.name %> [<%= map_url(@map) %>]
|
||||||
|
|
||||||
|
Make sense with Metamaps
|
||||||
|
|
||||||
|
|
|
@ -12,21 +12,34 @@
|
||||||
|
|
||||||
<div class="mapInfoStat">
|
<div class="mapInfoStat">
|
||||||
<div class="infoStatIcon mapContributors hoverForTip">
|
<div class="infoStatIcon mapContributors hoverForTip">
|
||||||
<% if @map.contributors.count == 0 %>
|
<% relevantPeople = @map.permission == "commons" ? @map.contributors : @map.editors %>
|
||||||
|
<% if relevantPeople.count == 0 %>
|
||||||
<img id="mapContribs" width="25" height="25" src="<%= asset_path('user.png'); %>" />
|
<img id="mapContribs" width="25" height="25" src="<%= asset_path('user.png'); %>" />
|
||||||
<% elsif @map.contributors.count == 1 %>
|
<% elsif relevantPeople.count == 1 %>
|
||||||
<img id="mapContribs" width="25" height="25" src="<%= @map.contributors[0].image.url(:thirtytwo) %>" />
|
<img id="mapContribs" width="25" height="25" src="<%= relevantPeople[0].image.url(:thirtytwo) %>" />
|
||||||
<% elsif @map.contributors.count == 2 %>
|
<% elsif relevantPeople.count == 2 %>
|
||||||
<img id="mapContribs" width="25" height="25" src="<%= @map.contributors[0].image.url(:thirtytwo) %>" class="multiple mTwo" />
|
<img id="mapContribs" width="25" height="25" src="<%= relevantPeople[0].image.url(:thirtytwo) %>" class="multiple mTwo" />
|
||||||
<% elsif @map.contributors.count > 2 %>
|
<% elsif relevantPeople.count > 2 %>
|
||||||
<img id="mapContribs" width="25" height="25" src="<%= @map.contributors[0].image.url(:thirtytwo) %>" class="multiple" />
|
<img id="mapContribs" width="25" height="25" src="<%= relevantPeople[0].image.url(:thirtytwo) %>" class="multiple" />
|
||||||
|
<% end %>
|
||||||
|
<span class="count"><%= relevantPeople.count %></span>
|
||||||
|
<div class="tip">
|
||||||
|
<ul><% relevantPeople.each_with_index do |c, index| %>
|
||||||
|
<li>
|
||||||
|
<a href="/explore/mapper/<%= c.id %>" > <img class="rtUserImage" width="25" height="25" src="<%= asset_path c.image.url(:thirtytwo) %>" />
|
||||||
|
<%= c.name %>
|
||||||
|
<% if @map.user == c %> (creator)<% end %>
|
||||||
|
</a>
|
||||||
|
<% if @map.user != c && @map.user == current_user %>
|
||||||
|
<span class="removeCollaborator" data-id=" + m.get('id') + "></span>
|
||||||
<% end %>
|
<% end %>
|
||||||
<span><%= @map.contributors.count %></span>
|
|
||||||
<div class="tip"> <ul><% @map.contributors.each_with_index do |c, index| %>
|
|
||||||
<li ><a href="/explore/mapper/<%= c.id %>" > <img class="rtUserImage" width="25" height="25" src="<%= asset_path c.image.url(:thirtytwo) %>" />
|
|
||||||
<%= c.name %></a>
|
|
||||||
</li>
|
</li>
|
||||||
<% end %></ul></div>
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
<% if @map.user == current_user %>
|
||||||
|
<div class="collabSearchField"><span class="addCollab"></span><input class="collaboratorSearchField" placeholder="Add a collaborator!"></input></div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="infoStatIcon mapTopics">
|
<div class="infoStatIcon mapTopics">
|
||||||
<%= @map.topics.count %>
|
<%= @map.topics.count %>
|
||||||
|
@ -35,7 +48,7 @@
|
||||||
<%= @map.synapses.count %>
|
<%= @map.synapses.count %>
|
||||||
</div>
|
</div>
|
||||||
<div class="infoStatIcon mapPermission <%= @map.permission %> hoverForTip">
|
<div class="infoStatIcon mapPermission <%= @map.permission %> hoverForTip">
|
||||||
<div class="tooltips">As the creator, you can change the permission of this map, but the permissions of the topics and synapses on it must be changed independently.</div>
|
<div class="tooltips">As the creator, you can change the permission of this map, and the permission of all the topics and synapses you have authority to change will change as well.</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfloat"></div>
|
<div class="clearfloat"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
15
app/views/maps/sharedmaps.html.erb
Normal file
15
app/views/maps/sharedmaps.html.erb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<% #
|
||||||
|
# @file
|
||||||
|
# Shows a list of current user's maps
|
||||||
|
# GET /explore/mine(.:format)
|
||||||
|
# %>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
Metamaps.Maps.Shared = <%= @maps.to_json.html_safe %>;
|
||||||
|
Metamaps.currentPage = "shared";
|
||||||
|
<% content_for :title, "Explore Shared Maps | Metamaps" %>
|
||||||
|
|
||||||
|
Metamaps.currentSection = "explore";
|
||||||
|
Metamaps.GlobalUI.Search.open();
|
||||||
|
Metamaps.GlobalUI.Search.lock();
|
||||||
|
</script>
|
|
@ -10,6 +10,7 @@
|
||||||
Metamaps.currentPage = <%= @map.id.to_s %>;
|
Metamaps.currentPage = <%= @map.id.to_s %>;
|
||||||
Metamaps.Active.Map = <%= @map.to_json.html_safe %>;
|
Metamaps.Active.Map = <%= @map.to_json.html_safe %>;
|
||||||
Metamaps.Mappers = <%= @allmappers.to_json.html_safe %>;
|
Metamaps.Mappers = <%= @allmappers.to_json.html_safe %>;
|
||||||
|
Metamaps.Collaborators = <%= @allcollaborators.to_json.html_safe %>;
|
||||||
Metamaps.Topics = <%= @alltopics.to_json.html_safe %>;
|
Metamaps.Topics = <%= @alltopics.to_json.html_safe %>;
|
||||||
Metamaps.Synapses = <%= @allsynapses.to_json.html_safe %>;
|
Metamaps.Synapses = <%= @allsynapses.to_json.html_safe %>;
|
||||||
Metamaps.Mappings = <%= @allmappings.to_json.html_safe %>;
|
Metamaps.Mappings = <%= @allmappings.to_json.html_safe %>;
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
<div class="permIcon" data-permission="commons">
|
<div class="permIcon" data-permission="commons">
|
||||||
<div id="newmap_co" class="mapCommonsIcon mapPermIcon selected">
|
<div id="newmap_co" class="mapCommonsIcon mapPermIcon selected">
|
||||||
<div class="tip">
|
<div class="tip">
|
||||||
Collaborate with other mappers on editing this map. Those without accounts can view this map.
|
Anyone with an account can edit this map. Anyone without an account can only view it.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h4>COMMONS</h4>
|
<h4>COMMONS</h4>
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
<div class="permIcon" data-permission="public">
|
<div class="permIcon" data-permission="public">
|
||||||
<div id="newmap_pu" class="mapPublicIcon mapPermIcon">
|
<div id="newmap_pu" class="mapPublicIcon mapPermIcon">
|
||||||
<div class="tip">
|
<div class="tip">
|
||||||
Anyone, with or without an account, can view this map but not edit anything.
|
Only people you allow can edit this map. Anyone can view it.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h4>PUBLIC</h4>
|
<h4>PUBLIC</h4>
|
||||||
|
@ -42,14 +42,14 @@
|
||||||
<div class="permIcon" data-permission="private">
|
<div class="permIcon" data-permission="private">
|
||||||
<div id="newmap_pr" class="mapPrivateIcon mapPermIcon">
|
<div id="newmap_pr" class="mapPrivateIcon mapPermIcon">
|
||||||
<div class="tip">
|
<div class="tip">
|
||||||
Only you can view or edit this map.
|
Only people you allow can edit this map. No one else can view it.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h4>PRIVATE</h4>
|
<h4>PRIVATE</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfloat"></div>
|
<div class="clearfloat"></div>
|
||||||
</div>
|
</div>
|
||||||
<p class="permText">Collaborate with other mappers on editing this map. Those without accounts can view this map.</p>
|
<p class="permText">Anyone with an account can edit this map. Anyone without an account can only view it.</p>
|
||||||
<div class="clearfloat"></div>
|
<div class="clearfloat"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
# jenkins machine prerequisites
|
# jenkins machine prerequisites
|
||||||
# sudo aptitude -q -y install libpq-dev
|
# sudo aptitude -q -y install libpq-dev
|
||||||
# install rvm with user gemsets
|
# install rvm with user gemsets
|
||||||
|
# install node and npm
|
||||||
|
|
||||||
source "$HOME/.rvm/scripts/rvm"
|
source "$HOME/.rvm/scripts/rvm"
|
||||||
rvm use $(cat .ruby-version) || \
|
rvm use $(cat .ruby-version) || \
|
||||||
|
@ -19,10 +20,15 @@ export RAILS_ENV=test
|
||||||
cp .example-env .env
|
cp .example-env .env
|
||||||
sed -i -e "s/DB_USERNAME='.*'/DB_USERNAME='jenkins'/" .env
|
sed -i -e "s/DB_USERNAME='.*'/DB_USERNAME='jenkins'/" .env
|
||||||
|
|
||||||
#test
|
# rspec tests
|
||||||
bundle install
|
bundle install
|
||||||
rake db:drop
|
rake db:drop
|
||||||
rake db:create
|
rake db:create
|
||||||
rake db:schema:load
|
rake db:schema:load
|
||||||
rake db:migrate
|
rake db:migrate
|
||||||
COVERAGE=on bundle exec rspec
|
COVERAGE=on bundle exec rspec
|
||||||
|
|
||||||
|
# javascript tests
|
||||||
|
cd app/assets/javascripts
|
||||||
|
npm install
|
||||||
|
npm test
|
||||||
|
|
|
@ -2,13 +2,9 @@ require File.expand_path('../boot', __FILE__)
|
||||||
|
|
||||||
require 'csv'
|
require 'csv'
|
||||||
require 'rails/all'
|
require 'rails/all'
|
||||||
require 'dotenv'
|
|
||||||
|
|
||||||
Bundler.require(*Rails.groups)
|
Bundler.require(*Rails.groups)
|
||||||
|
|
||||||
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
|
|
||||||
Dotenv.load ".env.#{ENV["RAILS_ENV"]}", '.env'
|
|
||||||
|
|
||||||
module Metamaps
|
module Metamaps
|
||||||
class Application < Rails::Application
|
class Application < Rails::Application
|
||||||
config.active_job.queue_adapter = :delayed_job
|
config.active_job.queue_adapter = :delayed_job
|
||||||
|
|
|
@ -30,7 +30,7 @@ Metamaps::Application.configure do
|
||||||
port: ENV['SMTP_PORT'],
|
port: ENV['SMTP_PORT'],
|
||||||
user_name: ENV['SMTP_USERNAME'],
|
user_name: ENV['SMTP_USERNAME'],
|
||||||
password: ENV['SMTP_PASSWORD'],
|
password: ENV['SMTP_PASSWORD'],
|
||||||
#domain: ENV['SMTP_DOMAIN']
|
domain: ENV['SMTP_DOMAIN'],
|
||||||
authentication: 'plain',
|
authentication: 'plain',
|
||||||
enable_starttls_auto: true,
|
enable_starttls_auto: true,
|
||||||
openssl_verify_mode: 'none' }
|
openssl_verify_mode: 'none' }
|
||||||
|
@ -41,6 +41,8 @@ Metamaps::Application.configure do
|
||||||
# Print deprecation notices to the Rails logger
|
# Print deprecation notices to the Rails logger
|
||||||
config.active_support.deprecation = :log
|
config.active_support.deprecation = :log
|
||||||
|
|
||||||
|
config.action_mailer.preview_path = '/vagrant/spec/mailers/previews'
|
||||||
|
|
||||||
# Expands the lines which load the assets
|
# Expands the lines which load the assets
|
||||||
config.assets.debug = true
|
config.assets.debug = true
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,4 +4,4 @@
|
||||||
# If you change this key, all old signed cookies will become invalid!
|
# If you change this key, all old signed cookies will become invalid!
|
||||||
# Make sure the secret is at least 30 characters and all random,
|
# Make sure the secret is at least 30 characters and all random,
|
||||||
# no regular words or you'll be exposed to dictionary attacks.
|
# no regular words or you'll be exposed to dictionary attacks.
|
||||||
Metamaps::Application.config.secret_key_base = '267c8a84f63963282f45bc3010eaddf027abfab58fc759d6e239c8005f85ee99d6d01b1ab6394cdee9ca7f8c9213a0cf91d3d8d3350f096123e2caccbcc0924f'
|
Metamaps::Application.config.secret_key_base = ENV['SECRET_KEY_BASE']
|
||||||
|
|
|
@ -40,13 +40,14 @@ Metamaps::Application.routes.draw do
|
||||||
post 'maps/:id/events/:event', to: 'maps#events'
|
post 'maps/:id/events/:event', to: 'maps#events'
|
||||||
get 'maps/:id/contains', to: 'maps#contains', as: :contains
|
get 'maps/:id/contains', to: 'maps#contains', as: :contains
|
||||||
post 'maps/:id/upload_screenshot', to: 'maps#screenshot', as: :screenshot
|
post 'maps/:id/upload_screenshot', to: 'maps#screenshot', as: :screenshot
|
||||||
|
post 'maps/:id/access', to: 'maps#access', as: :access, defaults: {format: :json}
|
||||||
|
|
||||||
get 'explore/active', to: 'maps#activemaps'
|
get 'explore/active', to: 'maps#activemaps'
|
||||||
get 'explore/featured', to: 'maps#featuredmaps'
|
get 'explore/featured', to: 'maps#featuredmaps'
|
||||||
get 'explore/mine', to: 'maps#mymaps'
|
get 'explore/mine', to: 'maps#mymaps'
|
||||||
|
get 'explore/shared', to: 'maps#sharedmaps'
|
||||||
get 'explore/mapper/:id', to: 'maps#usermaps'
|
get 'explore/mapper/:id', to: 'maps#usermaps'
|
||||||
|
|
||||||
|
|
||||||
devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords', sessions: 'devise/sessions' }, :skip => :sessions
|
devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords', sessions: 'devise/sessions' }, :skip => :sessions
|
||||||
|
|
||||||
devise_scope :user do
|
devise_scope :user do
|
||||||
|
|
10
db/migrate/20160331181959_create_user_maps.rb
Normal file
10
db/migrate/20160331181959_create_user_maps.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
class CreateUserMaps < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :user_maps do |t|
|
||||||
|
t.references :user, index: true
|
||||||
|
t.references :map, index: true
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,6 @@
|
||||||
|
class AddDefersToMapToTopicsAndSynapses < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :topics, :defer_to_map_id, :integer
|
||||||
|
add_column :synapses, :defer_to_map_id, :integer
|
||||||
|
end
|
||||||
|
end
|
14
db/schema.rb
14
db/schema.rb
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20160318141618) do
|
ActiveRecord::Schema.define(version: 20160401133937) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -182,6 +182,7 @@ ActiveRecord::Schema.define(version: 20160318141618) do
|
||||||
t.integer "user_id"
|
t.integer "user_id"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
t.integer "defer_to_map_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "synapses", ["node1_id", "node1_id"], name: "index_synapses_on_node1_id_and_node1_id", using: :btree
|
add_index "synapses", ["node1_id", "node1_id"], name: "index_synapses_on_node1_id_and_node1_id", using: :btree
|
||||||
|
@ -217,11 +218,22 @@ ActiveRecord::Schema.define(version: 20160318141618) do
|
||||||
t.string "audio_content_type"
|
t.string "audio_content_type"
|
||||||
t.integer "audio_file_size"
|
t.integer "audio_file_size"
|
||||||
t.datetime "audio_updated_at"
|
t.datetime "audio_updated_at"
|
||||||
|
t.integer "defer_to_map_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "topics", ["metacode_id"], name: "index_topics_on_metacode_id", using: :btree
|
add_index "topics", ["metacode_id"], name: "index_topics_on_metacode_id", using: :btree
|
||||||
add_index "topics", ["user_id"], name: "index_topics_on_user_id", using: :btree
|
add_index "topics", ["user_id"], name: "index_topics_on_user_id", using: :btree
|
||||||
|
|
||||||
|
create_table "user_maps", force: :cascade do |t|
|
||||||
|
t.integer "user_id"
|
||||||
|
t.integer "map_id"
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "user_maps", ["map_id"], name: "index_user_maps_on_map_id", using: :btree
|
||||||
|
add_index "user_maps", ["user_id"], name: "index_user_maps_on_user_id", using: :btree
|
||||||
|
|
||||||
create_table "users", force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "email"
|
t.string "email"
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
## Testing Javascript
|
||||||
|
|
||||||
|
Javascript tests are under construction, but you can read more in the README in `app/assets/javascripts`.
|
||||||
|
|
||||||
## Testing with RSpec
|
## Testing with RSpec
|
||||||
|
|
||||||
RSpec is a ruby gem that allows you to test your code base. This is great -
|
RSpec is a ruby gem that allows you to test your code base. This is great -
|
||||||
|
|
|
@ -303,7 +303,7 @@ Metamaps.Famous.build = function () {
|
||||||
var loggedIn = Metamaps.Active.Mapper ? 'Auth' : '';
|
var loggedIn = Metamaps.Active.Mapper ? 'Auth' : '';
|
||||||
|
|
||||||
|
|
||||||
if (section === "mine" || section === "active" || section === "featured") {
|
if (section === "mine" || section === "shared" || section === "active" || section === "featured") {
|
||||||
f.explore.surf.setContent(templates[section + loggedIn + 'Content']);
|
f.explore.surf.setContent(templates[section + loggedIn + 'Content']);
|
||||||
}
|
}
|
||||||
else if (section === "mapper") {
|
else if (section === "mapper") {
|
||||||
|
|
|
@ -19,16 +19,17 @@ t.logoContent += '</ul>';
|
||||||
|
|
||||||
/* logged in explore maps bars */
|
/* logged in explore maps bars */
|
||||||
t.mineAuthContent = '<a href="/explore/mine" class="active myMaps exploreMapsButton"><div class="exploreMapsIcon"></div>My Maps</a>';
|
t.mineAuthContent = '<a href="/explore/mine" class="active myMaps exploreMapsButton"><div class="exploreMapsIcon"></div>My Maps</a>';
|
||||||
|
t.mineAuthContent += '<a href="/explore/shared" class="sharedMaps exploreMapsButton"><div class="exploreMapsIcon"></div>Shared With Me</a>';
|
||||||
t.mineAuthContent += '<a href="/" class="activeMaps exploreMapsButton"><div class="exploreMapsIcon"></div>Recently Active</a>';
|
t.mineAuthContent += '<a href="/" class="activeMaps exploreMapsButton"><div class="exploreMapsIcon"></div>Recently Active</a>';
|
||||||
t.mineAuthContent += '<a href="/explore/featured" class="featuredMaps exploreMapsButton"><div class="exploreMapsIcon"></div>Featured</a>';
|
|
||||||
|
t.sharedAuthContent = '<a href="/explore/mine" class="myMaps exploreMapsButton"><div class="exploreMapsIcon"></div>My Maps</a>';
|
||||||
|
t.sharedAuthContent += '<a href="/explore/shared" class="active sharedMaps exploreMapsButton"><div class="exploreMapsIcon"></div>Shared With Me</a>';
|
||||||
|
t.sharedAuthContent += '<a href="/" class="activeMaps exploreMapsButton"><div class="exploreMapsIcon"></div>Recently Active</a>';
|
||||||
|
|
||||||
t.activeAuthContent = '<a href="/explore/mine" class="myMaps exploreMapsButton"><div class="exploreMapsIcon"></div>My Maps</a>';
|
t.activeAuthContent = '<a href="/explore/mine" class="myMaps exploreMapsButton"><div class="exploreMapsIcon"></div>My Maps</a>';
|
||||||
|
t.activeAuthContent += '<a href="/explore/shared" class="sharedMaps exploreMapsButton"><div class="exploreMapsIcon"></div>Shared With Me</a>';
|
||||||
t.activeAuthContent += '<a href="/" class="active activeMaps exploreMapsButton"><div class="exploreMapsIcon"></div>Recently Active</a>';
|
t.activeAuthContent += '<a href="/" class="active activeMaps exploreMapsButton"><div class="exploreMapsIcon"></div>Recently Active</a>';
|
||||||
t.activeAuthContent += '<a href="/explore/featured" class="featuredMaps exploreMapsButton"><div class="exploreMapsIcon"></div>Featured</a>';
|
|
||||||
|
|
||||||
t.featuredAuthContent = '<a href="/explore/mine" class="myMaps exploreMapsButton"><div class="exploreMapsIcon"></div>My Maps</a>';
|
|
||||||
t.featuredAuthContent += '<a href="/" class="activeMaps exploreMapsButton"><div class="exploreMapsIcon"></div>Recently Active</a>';
|
|
||||||
t.featuredAuthContent += '<a href="/explore/featured" class="active featuredMaps exploreMapsButton"><div class="exploreMapsIcon"></div>Featured</a>';
|
|
||||||
|
|
||||||
/* apps bars */
|
/* apps bars */
|
||||||
t.registeredAppsContent = '<a href="/oauth/applications" class="active activeMaps exploreMapsButton" data-bypass="true"><div class="exploreMapsIcon"></div>Registered Apps</a>';
|
t.registeredAppsContent = '<a href="/oauth/applications" class="active activeMaps exploreMapsButton" data-bypass="true"><div class="exploreMapsIcon"></div>Registered Apps</a>';
|
||||||
|
|
5
spec/mailers/map_mailer_spec.rb
Normal file
5
spec/mailers/map_mailer_spec.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
RSpec.describe MapMailer, type: :mailer do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
6
spec/mailers/previews/map_mailer_preview.rb
Normal file
6
spec/mailers/previews/map_mailer_preview.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
# Preview all emails at http://localhost:3000/rails/mailers/map_mailer
|
||||||
|
class MapMailerPreview < ActionMailer::Preview
|
||||||
|
def invite_to_edit_email
|
||||||
|
MapMailer.invite_to_edit_email(Map.first, User.first, User.second)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue