2016-10-02 17:58:37 +08:00
|
|
|
/* global Metamaps */
|
2016-09-22 23:51:33 +08:00
|
|
|
|
2016-09-23 00:20:05 +08:00
|
|
|
import Active from '../Active'
|
|
|
|
import Filter from '../Filter'
|
2016-10-02 17:58:37 +08:00
|
|
|
import { InfoBox } from '../Map'
|
|
|
|
|
|
|
|
import Map from './Map'
|
|
|
|
import MapCollection from './MapCollection'
|
|
|
|
import Message from './Message'
|
|
|
|
import MessageCollection from './MessageCollection'
|
|
|
|
import Mapper from './Mapper'
|
|
|
|
import MapperCollection from './MapperCollection'
|
|
|
|
import Metacode from './Metacode'
|
|
|
|
import MetacodeCollection from './MetacodeCollection'
|
|
|
|
import Topic from './Topic'
|
|
|
|
import TopicCollection from './TopicCollection'
|
|
|
|
import Synapse from './Synapse'
|
|
|
|
import SynapseCollection from './SynapseCollection'
|
|
|
|
import Mapping from './Mapping'
|
|
|
|
import MappingCollection from './MappingCollection'
|
2016-09-23 00:20:05 +08:00
|
|
|
|
2016-03-27 19:46:36 +08:00
|
|
|
/*
|
2016-10-02 17:58:37 +08:00
|
|
|
* DataModel.js
|
2016-03-27 19:46:36 +08:00
|
|
|
*
|
|
|
|
* Dependencies:
|
2016-08-01 13:38:57 -04:00
|
|
|
* - Metamaps.Collaborators
|
2016-04-24 11:50:35 -04:00
|
|
|
* - Metamaps.Creators
|
2016-08-01 13:38:57 -04:00
|
|
|
* - Metamaps.Mappers
|
|
|
|
* - Metamaps.Mappings
|
|
|
|
* - Metamaps.Metacodes
|
2016-04-24 11:50:35 -04:00
|
|
|
* - Metamaps.Synapses
|
2016-08-01 13:38:57 -04:00
|
|
|
* - Metamaps.Topics
|
2016-03-27 19:46:36 +08:00
|
|
|
*/
|
|
|
|
|
2016-10-02 17:58:37 +08:00
|
|
|
const DataModel = {
|
|
|
|
Map: Map,
|
|
|
|
MapCollection: MapCollection,
|
|
|
|
Message: Message,
|
|
|
|
MessageCollection: MessageCollection,
|
|
|
|
Mapper: Mapper,
|
|
|
|
MapperCollection: MapperCollection,
|
|
|
|
Metacode: Metacode,
|
|
|
|
MetacodeCollection: MetacodeCollection,
|
|
|
|
Topic: Topic,
|
|
|
|
TopicCollection: TopicCollection,
|
|
|
|
Synapse: Synapse,
|
|
|
|
SynapseCollection: SynapseCollection,
|
|
|
|
Mapping: Mapping,
|
|
|
|
MappingCollection: MappingCollection,
|
|
|
|
|
2016-10-02 18:21:56 +08:00
|
|
|
init: function () {
|
2016-10-02 17:58:37 +08:00
|
|
|
var self = DataModel
|
|
|
|
|
|
|
|
Metamaps.Metacodes = Metamaps.Metacodes ? new self.MetacodeCollection(Metamaps.Metacodes) : new self.MetacodeCollection()
|
|
|
|
|
|
|
|
// attach collection event listeners
|
|
|
|
Metamaps.Topics = Metamaps.Topics ? new self.TopicCollection(Metamaps.Topics) : new self.TopicCollection()
|
2016-04-24 11:50:35 -04:00
|
|
|
Metamaps.Topics.on('add remove', function (topic) {
|
2016-09-23 00:20:05 +08:00
|
|
|
InfoBox.updateNumbers()
|
|
|
|
Filter.checkMetacodes()
|
|
|
|
Filter.checkMappers()
|
2016-04-24 11:50:35 -04:00
|
|
|
})
|
|
|
|
|
2016-10-02 17:58:37 +08:00
|
|
|
Metamaps.Synapses = Metamaps.Synapses ? new self.SynapseCollection(Metamaps.Synapses) : new self.SynapseCollection()
|
2016-04-24 11:50:35 -04:00
|
|
|
Metamaps.Synapses.on('add remove', function (synapse) {
|
2016-09-23 00:20:05 +08:00
|
|
|
InfoBox.updateNumbers()
|
|
|
|
Filter.checkSynapses()
|
|
|
|
Filter.checkMappers()
|
2016-04-24 11:50:35 -04:00
|
|
|
})
|
|
|
|
|
2016-09-23 00:20:05 +08:00
|
|
|
if (Active.Map) {
|
2016-10-02 17:58:37 +08:00
|
|
|
Metamaps.Mappings = Metamaps.Mappings ? new self.MappingCollection(Metamaps.Mappings) : new self.MappingCollection()
|
2016-04-24 11:50:35 -04:00
|
|
|
Metamaps.Mappings.on('add remove', function (mapping) {
|
2016-09-23 00:20:05 +08:00
|
|
|
InfoBox.updateNumbers()
|
|
|
|
Filter.checkSynapses()
|
|
|
|
Filter.checkMetacodes()
|
|
|
|
Filter.checkMappers()
|
2016-04-24 11:50:35 -04:00
|
|
|
})
|
|
|
|
}
|
2016-10-02 17:58:37 +08:00
|
|
|
|
|
|
|
Metamaps.Mappers = Metamaps.Mappers ? new self.MapperCollection(Metamaps.Mappers) : new self.MapperCollection()
|
|
|
|
Metamaps.Collaborators = Metamaps.Collaborators ? new self.MapperCollection(Metamaps.Collaborators) : new self.MapperCollection()
|
|
|
|
Metamaps.Creators = Metamaps.Creators ? new self.MapperCollection(Metamaps.Creators) : new self.MapperCollection()
|
|
|
|
|
|
|
|
if (Active.Map) {
|
|
|
|
Active.Map = new self.Map(Active.Map)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Active.Topic) {
|
|
|
|
Active.Topic = new self.Topic(Active.Topic)
|
|
|
|
}
|
2016-04-24 11:50:35 -04:00
|
|
|
}
|
2016-10-02 17:58:37 +08:00
|
|
|
}
|
|
|
|
|
2016-10-02 18:21:56 +08:00
|
|
|
export { Map, MapCollection, Mapper, MapperCollection, Mapping, MappingCollection, Message, MessageCollection, Metacode, MetacodeCollection, Synapse, SynapseCollection, Topic, TopicCollection }
|
2016-09-22 15:21:59 +08:00
|
|
|
|
2016-10-02 17:16:02 +08:00
|
|
|
export default DataModel
|