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-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 21:41:05 +08:00
|
|
|
Collaborators: new MapperCollection(),
|
|
|
|
Creators: new MapperCollection(),
|
2016-10-02 22:28:00 +08:00
|
|
|
Mappers: new MapperCollection(),
|
|
|
|
Mappings: new MappingCollection(),
|
|
|
|
Messages: [],
|
|
|
|
Metacodes: new MetacodeCollection(),
|
|
|
|
Stars: [],
|
|
|
|
Synapses: new SynapseCollection(),
|
|
|
|
Topics: new TopicCollection(),
|
2016-10-02 21:41:05 +08:00
|
|
|
|
|
|
|
init: function (serverData) {
|
2016-10-02 17:58:37 +08:00
|
|
|
var self = DataModel
|
|
|
|
|
2016-10-02 22:28:00 +08:00
|
|
|
if (serverData.Collaborators) self.Collaborators = new MapperCollection(serverData.Collaborators)
|
|
|
|
if (serverData.Creators) self.Creators = new MapperCollection(serverData.Creators)
|
|
|
|
if (serverData.Mappers) self.Mappers = new MapperCollection(serverData.Mappers)
|
|
|
|
if (serverData.Mappings) self.Mappings = new MappingCollection(serverData.Mappings)
|
|
|
|
if (serverData.Messages) self.Messages = serverData.Messages
|
2016-10-02 21:41:05 +08:00
|
|
|
if (serverData.Metacodes) self.Metacodes = new MetacodeCollection(serverData.Metacodes)
|
2016-10-02 22:28:00 +08:00
|
|
|
if (serverData.Stars) self.Stars = serverData.Stars
|
|
|
|
if (serverData.Synapses) self.Synapses = new SynapseCollection(serverData.Synapses)
|
2016-10-02 21:41:05 +08:00
|
|
|
if (serverData.Topics) self.Topics = new TopicCollection(serverData.Topics)
|
2016-10-02 22:28:00 +08:00
|
|
|
|
|
|
|
self.attachCollectionEvents()
|
|
|
|
},
|
|
|
|
|
|
|
|
attachCollectionEvents: function () {
|
|
|
|
var self = DataModel
|
2016-10-02 21:41:05 +08:00
|
|
|
self.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 21:41:05 +08:00
|
|
|
self.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-10-02 21:41:05 +08:00
|
|
|
self.Mappings.on('add remove', function (mapping) {
|
|
|
|
InfoBox.updateNumbers()
|
|
|
|
Filter.checkSynapses()
|
|
|
|
Filter.checkMetacodes()
|
|
|
|
Filter.checkMappers()
|
|
|
|
})
|
2016-04-24 11:50:35 -04:00
|
|
|
}
|
2016-10-02 17:58:37 +08:00
|
|
|
}
|
|
|
|
|
2016-10-02 21:41:05 +08:00
|
|
|
// Note: Topics, Metacodes, Synapses, Mappers, Mappings, Collaborators, Creators are not exported
|
|
|
|
// You can access them by importing DataModel
|
|
|
|
|
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
|