Compare commits
28 Commits
prototype_
...
master
Author | SHA1 | Date |
---|---|---|
Hendrik Fellerhoff | f1bae83556 | |
Hendrik Fellerhoff | 8248804ac7 | |
Lucas Pleß | 1921417667 | |
Lucas Pleß | 03ed17d10d | |
Lucas Pleß | 0cb8e585af | |
Lucas Pleß | ec3620df77 | |
Hendrik Fellerhoff | 60d5fc8323 | |
Hendrik Fellerhoff | 4e26793524 | |
Hendrik Fellerhoff | b11e96dc64 | |
Hendrik Fellerhoff | d6b7f80c93 | |
Hendrik Fellerhoff | b21670aea2 | |
Hendrik Fellerhoff | 274fdf53c1 | |
Hendrik Fellerhoff | efb07b64da | |
Hendrik Fellerhoff | 51005c7f7b | |
Hendrik Fellerhoff | c0782344e7 | |
Hendrik Fellerhoff | 594e545080 | |
Hendrik Fellerhoff | 67d82c4af6 | |
Hendrik Fellerhoff | 855efcd572 | |
Lucas Pleß | 55fe1dca17 | |
Hendrik Fellerhoff | a833a3b6a4 | |
Lucas Pleß | 04f77c6553 | |
Lucas Pleß | c09e08200f | |
Lucas Pleß | 793cb2a940 | |
Lucas Pleß | 351f1b1816 | |
Lucas Pleß | 4f755abce6 | |
Lucas Pleß | 8b362e1ebc | |
Lucas Pleß | 64f90ce109 | |
Juergen Jung | 2c259d8bfc |
45
pom.xml
45
pom.xml
|
@ -47,6 +47,13 @@
|
|||
<version>${org.springframework.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${org.springframework.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
|
@ -73,15 +80,9 @@
|
|||
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
<version>1.0.0.GA</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>4.1.0.Final</version>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-orm</artifactId>
|
||||
<version>${org.springframework.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -90,12 +91,32 @@
|
|||
<version>3.6.7.Final</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-commons-annotations</artifactId>
|
||||
<version>3.2.0.Final</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hibernate.javax.persistence</groupId>
|
||||
<artifactId>hibernate-jpa-2.0-api</artifactId>
|
||||
<version>1.0.1.Final</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hsqldb</groupId>
|
||||
<artifactId>hsqldb</artifactId>
|
||||
<version>1.8.0.10</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.3.160</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
|
@ -147,11 +168,7 @@
|
|||
<artifactId>jetty-server</artifactId>
|
||||
<version>${jettyVersion}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-orm</artifactId>
|
||||
<version>3.0.6.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ public class ByteUtils {
|
|||
private final byte[] data;
|
||||
|
||||
public ByteUtils(byte[] data) {
|
||||
this.data = data;
|
||||
this.data = data.clone();
|
||||
}
|
||||
|
||||
public static int byteToUint(byte b) {
|
||||
|
@ -40,7 +40,7 @@ public class ByteUtils {
|
|||
}
|
||||
|
||||
public final byte[] getBytes() {
|
||||
return data;
|
||||
return data.clone();
|
||||
}
|
||||
|
||||
public final int getInt16(int offset) {
|
||||
|
|
|
@ -37,7 +37,7 @@ public abstract class ArtNetPacket {
|
|||
}
|
||||
|
||||
public final void setData(byte[] data) {
|
||||
this.data = new ByteUtils(data);
|
||||
this.data = new ByteUtils(data.clone());
|
||||
}
|
||||
|
||||
public final PacketType getType() {
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
|
||||
package de.ctdo.bunti.artnet.packets;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public enum PacketType {
|
||||
|
||||
ART_POLL(0x2000, null),
|
||||
|
@ -47,6 +50,8 @@ public enum PacketType {
|
|||
|
||||
private final int opCode;
|
||||
private final Class<? extends ArtNetPacket> packetClass;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PacketType.class);
|
||||
|
||||
|
||||
private PacketType(int code, Class<? extends ArtNetPacket> clazz) {
|
||||
opCode = code;
|
||||
|
@ -59,9 +64,9 @@ public enum PacketType {
|
|||
try {
|
||||
p = packetClass.newInstance();
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error("Could not instanciate ArtNetPacket: ",e);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error("Could not instanciate ArtNetPacket: ",e);
|
||||
}
|
||||
}
|
||||
return p;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package de.ctdo.bunti.control;
|
||||
|
||||
import de.ctdo.bunti.model.BuntiDevice;
|
||||
import de.ctdo.bunti.model.Room;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
@ -12,4 +13,7 @@ public interface BuntiController {
|
|||
|
||||
boolean updateDeviceData(int deviceId, Map<String, Object> options);
|
||||
|
||||
Collection<Room> getAllRooms();
|
||||
Room getRoomById(int roomId);
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import de.ctdo.bunti.dao.BuntiDevicesDAO;
|
|||
import de.ctdo.bunti.model.*;
|
||||
|
||||
@Component
|
||||
public class BuntiControllerImpl implements BuntiController, ApplicationEventPublisherAware {
|
||||
public class BuntiControllerImpl implements BuntiController, ApplicationEventPublisherAware {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(BuntiControllerImpl.class);
|
||||
private ApplicationEventPublisher applicationEventPublisher = null;
|
||||
private BuntiDevicesDAO devicesDAO;
|
||||
|
@ -54,6 +54,16 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPub
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Room> getAllRooms() {
|
||||
return roomsDAO.getRooms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Room getRoomById(int roomId) {
|
||||
return roomsDAO.getRoom(roomId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<BuntiDevice> getAllDevices() {
|
||||
return devicesDAO.getAllDevices();
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
package de.ctdo.bunti.dao;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import de.ctdo.bunti.model.*;
|
||||
|
||||
public interface BuntiDevicesDAO {
|
||||
|
||||
Collection<BuntiDevice> getAllDevices();
|
||||
Collection<BuntiDMXDevice> getAllDMXDevices();
|
||||
List<BuntiDevice> getAllDevices();
|
||||
List<BuntiDMXDevice> getAllDMXDevices();
|
||||
BuntiDevice getDeviceById(int deviceId);
|
||||
|
||||
void addDevice(BuntiDevice device);
|
||||
void removeDevice(int deviceId);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,63 +1,36 @@
|
|||
package de.ctdo.bunti.dao;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import de.ctdo.bunti.model.*;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public final class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(BuntiDevicesDAOImpl.class);
|
||||
private List<BuntiDevice> devices = new ArrayList<BuntiDevice>();
|
||||
|
||||
public BuntiDevicesDAOImpl() {
|
||||
addDummyDevices();
|
||||
}
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
|
||||
|
||||
private void addDummyDevices() {
|
||||
int deviceID = 0;
|
||||
|
||||
devices.add(new Par56Spot(deviceID++, 1, "Par56 Lampe 1"));
|
||||
devices.add(new Par56Spot(deviceID++, 6, "Par56 Lampe 2"));
|
||||
devices.add(new Par56Spot(deviceID++, 11, "Par56 Lampe 3"));
|
||||
devices.add(new Par56Spot(deviceID++, 16, "Par56 Lampe 4"));
|
||||
devices.add(new Strobe1500(deviceID++, 21, "Stroboskop 1"));
|
||||
devices.add(new Par56Spot(deviceID, 508, "Par56 Lampe 5"));
|
||||
LOGGER.debug("added dummy devices in DAO");
|
||||
}
|
||||
|
||||
public final class BuntiDevicesDAOImpl extends HibernateDaoSupport implements BuntiDevicesDAO {
|
||||
|
||||
@Override
|
||||
public Collection<BuntiDMXDevice> getAllDMXDevices() {
|
||||
List<BuntiDMXDevice> list = new ArrayList<BuntiDMXDevice>();
|
||||
for (BuntiDevice device : devices) {
|
||||
if( device instanceof BuntiDMXDevice ) {
|
||||
list.add((BuntiDMXDevice) device);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
public List<BuntiDMXDevice> getAllDMXDevices() {
|
||||
return getHibernateTemplate().loadAll(BuntiDMXDevice.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<BuntiDevice> getAllDevices() {
|
||||
return Collections.unmodifiableCollection(devices);
|
||||
public List<BuntiDevice> getAllDevices() {
|
||||
return getHibernateTemplate().loadAll(BuntiDevice.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuntiDevice getDeviceById(int deviceId) {
|
||||
for (BuntiDevice dev : devices) {
|
||||
if(dev.getDeviceId() == deviceId) {
|
||||
return dev;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return getHibernateTemplate().get(BuntiDevice.class,deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDevice(BuntiDevice device) {
|
||||
getHibernateTemplate().save(device);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDevice(int deviceId) {
|
||||
getHibernateTemplate().delete(getDeviceById(deviceId));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,16 +4,9 @@ import de.ctdo.bunti.model.Room;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: lucas
|
||||
* @date: 15.03.12 21:55
|
||||
*/
|
||||
public interface RoomsDAO {
|
||||
|
||||
List<Room> getRooms();
|
||||
Room getRoom(int id);
|
||||
Room addRoom(Room room);
|
||||
void removeRoom(int id);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,17 +2,10 @@ package de.ctdo.bunti.dao;
|
|||
|
||||
import de.ctdo.bunti.model.Room;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public final class RoomsDAOImpl extends HibernateDaoSupport implements RoomsDAO {
|
||||
|
||||
public RoomsDAOImpl() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Room> getRooms() {
|
||||
return getHibernateTemplate().loadAll(Room.class);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package de.ctdo.bunti.dmx;
|
||||
|
||||
import de.ctdo.bunti.dmx.model.DMXChannel;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package de.ctdo.bunti.dmx;
|
||||
package de.ctdo.bunti.dmx.model;
|
||||
|
||||
public class DMXChannel {
|
||||
private int offset;
|
|
@ -1,28 +1,30 @@
|
|||
package de.ctdo.bunti.model;
|
||||
|
||||
import de.ctdo.bunti.dmx.DMX;
|
||||
import de.ctdo.bunti.dmx.DMXChannel;
|
||||
import de.ctdo.bunti.dmx.model.DMXChannel;
|
||||
import de.ctdo.bunti.dmx.DMXChannels;
|
||||
import org.codehaus.jackson.annotate.JsonIgnore;
|
||||
import org.hibernate.annotations.Entity;
|
||||
|
||||
import javax.persistence.Transient;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@Entity
|
||||
public abstract class BuntiDMXDevice extends BuntiDevice {
|
||||
private int startAddress;
|
||||
private final DMXChannels dmxChannels = new DMXChannels();
|
||||
|
||||
public BuntiDMXDevice(int deviceId, int startAddress, String name) {
|
||||
super(deviceId, name);
|
||||
setStartAddress(startAddress);
|
||||
public BuntiDMXDevice() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the DMX start address for this device
|
||||
* @return The address value from 1 to max 512
|
||||
*/
|
||||
public final int getStartAddress() {
|
||||
public int getStartAddress() {
|
||||
return startAddress;
|
||||
}
|
||||
|
||||
|
@ -31,7 +33,7 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
|
|||
* @param startAddress The address value from 1 to max 512
|
||||
* @return True on success, false if start address is wrong
|
||||
*/
|
||||
public final boolean setStartAddress(int startAddress) {
|
||||
public boolean setStartAddress(int startAddress) {
|
||||
if(startAddress < DMX.DMX_CHANNEL_INDEX_MIN ||
|
||||
startAddress - 1 + dmxChannels.getCount() > DMX.DMX_CHANNEL_INDEX_MAX) {
|
||||
return false;
|
||||
|
@ -62,6 +64,8 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
|
|||
* @param name The channel name to get the value from.
|
||||
* @return The desired channel value.
|
||||
*/
|
||||
@JsonIgnore
|
||||
@Transient
|
||||
protected final int getChannelValueByName(String name) {
|
||||
DMXChannel dx = dmxChannels.getChannelByName(name);
|
||||
if (dx != null) {
|
||||
|
@ -75,6 +79,7 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
|
|||
* @return The channel data with startaddress+offset of every channel
|
||||
*/
|
||||
@JsonIgnore
|
||||
@Transient
|
||||
public Map<Integer, Integer> getChannelData() {
|
||||
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
|
||||
|
||||
|
@ -106,6 +111,18 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Transient
|
||||
@Override
|
||||
public final Map<String, Object> getOptions() {
|
||||
Map<String, Object> options = new HashMap<String, Object>();
|
||||
|
||||
for(DMXChannel channel: dmxChannels.getAllChannels()) {
|
||||
options.put(channel.getName(), channel.getValue());
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a channel to this DMX Device
|
||||
* used internally by subclasses to define their structure
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package de.ctdo.bunti.model;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -7,43 +8,53 @@ import java.util.Map;
|
|||
* Maybe this is a lamp, or a switchable power source, or a strobe, ...
|
||||
* @author lucas
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "devices")
|
||||
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
|
||||
public abstract class BuntiDevice {
|
||||
private int deviceId;
|
||||
private int id;
|
||||
private String deviceName;
|
||||
private String picture;
|
||||
|
||||
public BuntiDevice(int deviceId, String deviceName) {
|
||||
this.deviceId = deviceId;
|
||||
this.deviceName = deviceName;
|
||||
public BuntiDevice() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the type of this device
|
||||
* @return a string with the class name (=the Type)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
@Transient
|
||||
public final String getType() {
|
||||
String FQClassName = this.getClass().getName();
|
||||
int firstChar = FQClassName.lastIndexOf ('.') + 1;
|
||||
String fqClassName = this.getClass().getName();
|
||||
int firstChar = fqClassName.lastIndexOf ('.') + 1;
|
||||
if ( firstChar > 0 ) {
|
||||
FQClassName = FQClassName.substring ( firstChar );
|
||||
fqClassName = fqClassName.substring ( firstChar );
|
||||
}
|
||||
return FQClassName;
|
||||
return fqClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the device Id
|
||||
* @return the device Id
|
||||
*/
|
||||
public final int getDeviceId() {
|
||||
return deviceId;
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "BUNTIDEVICE_ID", updatable=false, nullable=false)
|
||||
public final int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public final void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the device name
|
||||
* @return The name of the device
|
||||
*/
|
||||
public final String getDeviceName() {
|
||||
public String getDeviceName() {
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
|
@ -51,7 +62,7 @@ public abstract class BuntiDevice {
|
|||
* Sets the device Name
|
||||
* @param deviceName a String with the device name
|
||||
*/
|
||||
public final void setDeviceName(String deviceName) {
|
||||
public void setDeviceName(String deviceName) {
|
||||
this.deviceName = deviceName;
|
||||
}
|
||||
|
||||
|
@ -59,7 +70,7 @@ public abstract class BuntiDevice {
|
|||
* Get the relative URL to the picture of this device
|
||||
* @return the relative URL to the picture
|
||||
*/
|
||||
public final String getPicture() {
|
||||
public String getPicture() {
|
||||
return picture;
|
||||
}
|
||||
|
||||
|
@ -67,7 +78,7 @@ public abstract class BuntiDevice {
|
|||
* Get the relative URL to the picture of this device
|
||||
* @param picture The relative URL to the picture
|
||||
*/
|
||||
public final void setPicture(String picture) {
|
||||
public void setPicture(String picture) {
|
||||
this.picture = picture;
|
||||
}
|
||||
|
||||
|
@ -90,4 +101,8 @@ public abstract class BuntiDevice {
|
|||
public abstract boolean setValuesFromOptions(Map<String, Object> options);
|
||||
|
||||
|
||||
@Transient
|
||||
public abstract Map<String, Object> getOptions();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
package de.ctdo.bunti.model;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Transient;
|
||||
import java.util.Map;
|
||||
|
||||
@Entity
|
||||
public abstract class BuntiSwitchingDevice extends BuntiDevice {
|
||||
private static final String OPTION_STATE = "state";
|
||||
|
||||
private boolean state = false;
|
||||
|
||||
public BuntiSwitchingDevice(int deviceId, String deviceName) {
|
||||
super(deviceId, deviceName);
|
||||
public BuntiSwitchingDevice() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public final boolean setValuesFromOptions(Map<String, Object> options) {
|
||||
|
||||
|
@ -30,6 +30,7 @@ public abstract class BuntiSwitchingDevice extends BuntiDevice {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public boolean isState() {
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
package de.ctdo.bunti.model;
|
||||
|
||||
import de.ctdo.bunti.dmx.DMX;
|
||||
import de.ctdo.bunti.dmx.DMXChannel;
|
||||
import de.ctdo.bunti.dmx.model.DMXChannel;
|
||||
import org.codehaus.jackson.annotate.JsonIgnore;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
@Entity
|
||||
public class Par56Spot extends BuntiDMXDevice {
|
||||
|
||||
private static final String CHANNEL_MODE = "mode";
|
||||
|
@ -11,8 +16,12 @@ public class Par56Spot extends BuntiDMXDevice {
|
|||
private static final String CHANNEL_BLUE = "blue";
|
||||
private static final String CHANNEL_SPEED = "speed";
|
||||
|
||||
public Par56Spot(int deviceId, int startAddress, String deviceName) {
|
||||
super(deviceId, startAddress, deviceName);
|
||||
public Par56Spot() {
|
||||
super();
|
||||
addChannels();
|
||||
}
|
||||
|
||||
private void addChannels() {
|
||||
int offset = 0;
|
||||
addChannel(new DMXChannel(offset++, CHANNEL_MODE));
|
||||
addChannel(new DMXChannel(offset++, CHANNEL_RED));
|
||||
|
@ -33,14 +42,20 @@ public class Par56Spot extends BuntiDMXDevice {
|
|||
setChannelValueByName(CHANNEL_BLUE, value);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Transient
|
||||
public final int getRed() {
|
||||
return getChannelValueByName(CHANNEL_RED);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Transient
|
||||
public final int getGreen() {
|
||||
return getChannelValueByName(CHANNEL_GREEN);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Transient
|
||||
public final int getBlue() {
|
||||
return getChannelValueByName(CHANNEL_BLUE);
|
||||
}
|
||||
|
@ -67,7 +82,7 @@ public class Par56Spot extends BuntiDMXDevice {
|
|||
public final String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Par56Spot ");
|
||||
sb.append(getDeviceId());
|
||||
sb.append(getId());
|
||||
sb.append(", ");
|
||||
sb.append(getDeviceName());
|
||||
sb.append(" [");
|
||||
|
|
|
@ -1,16 +1,23 @@
|
|||
package de.ctdo.bunti.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.persistence.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@Entity
|
||||
@Table( name = "rooms" )
|
||||
public final class Room {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private String floor;
|
||||
private int xCord;
|
||||
private int yCord;
|
||||
private List<BuntiDevice> devices = new ArrayList<BuntiDevice>();
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "ROOM_ID", updatable=false, nullable=false)
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -19,6 +26,7 @@ public final class Room {
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
@Column( name = "roomName")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -26,27 +34,63 @@ public final class Room {
|
|||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean addDevice(BuntiDevice device) {
|
||||
return devices.add(device);
|
||||
}
|
||||
|
||||
public boolean removeDevice(BuntiDevice device) {
|
||||
return devices.remove(device);
|
||||
|
||||
public int getxCord() {
|
||||
return xCord;
|
||||
}
|
||||
|
||||
public void setxCord(int xCord) {
|
||||
this.xCord = xCord;
|
||||
}
|
||||
|
||||
public int getyCord() {
|
||||
return yCord;
|
||||
}
|
||||
|
||||
public void setyCord(int yCord) {
|
||||
this.yCord = yCord;
|
||||
}
|
||||
|
||||
|
||||
public String getFloor() {
|
||||
return floor;
|
||||
}
|
||||
|
||||
public void setFloor(String floor) {
|
||||
this.floor = floor;
|
||||
}
|
||||
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, targetEntity = BuntiDevice.class)
|
||||
@JoinTable(name = "ROOM_BUNTIDEVICE",
|
||||
joinColumns = { @JoinColumn(name = "ROOM_ID") },
|
||||
inverseJoinColumns = { @JoinColumn(name = "BUNTIDEVICE_ID") })
|
||||
public List<BuntiDevice> getDevices() {
|
||||
return Collections.unmodifiableList(this.devices);
|
||||
}
|
||||
|
||||
public void setDevices(List<BuntiDevice> devices) {
|
||||
this.devices = devices;
|
||||
}
|
||||
|
||||
|
||||
@Transient
|
||||
public boolean addDevice(BuntiDevice device) {
|
||||
return getDevices().add(device);
|
||||
}
|
||||
|
||||
@Transient
|
||||
public boolean removeDevice(BuntiDevice device) {
|
||||
return getDevices().remove(device);
|
||||
}
|
||||
|
||||
@Transient
|
||||
public BuntiDevice getDevice(int id) {
|
||||
for (BuntiDevice device: devices) {
|
||||
if( device.getDeviceId() == id) {
|
||||
for (BuntiDevice device: getDevices()) {
|
||||
if( device.getId() == id) {
|
||||
return device;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Collection<BuntiDevice> getDeviceList() {
|
||||
return Collections.unmodifiableList(devices);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,17 +1,25 @@
|
|||
package de.ctdo.bunti.model;
|
||||
|
||||
import de.ctdo.bunti.dmx.DMX;
|
||||
import de.ctdo.bunti.dmx.DMXChannel;
|
||||
import de.ctdo.bunti.dmx.model.DMXChannel;
|
||||
import org.codehaus.jackson.annotate.JsonIgnore;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
@Entity
|
||||
public class Strobe1500 extends BuntiDMXDevice {
|
||||
|
||||
private static final String CHANNEL_SPEED = "speed";
|
||||
private static final String CHANNEL_INTENSITY = "intensity";
|
||||
private static final String CHANNEL_MODE = "mode";
|
||||
|
||||
public Strobe1500(int deviceId, int startAddress, String deviceName) {
|
||||
super(deviceId, startAddress, deviceName);
|
||||
public Strobe1500() {
|
||||
super();
|
||||
addChannels();
|
||||
}
|
||||
|
||||
private void addChannels() {
|
||||
addChannel(new DMXChannel(0, CHANNEL_SPEED));
|
||||
addChannel(new DMXChannel(1, CHANNEL_INTENSITY));
|
||||
addChannel(new DMXChannel(2, CHANNEL_MODE));
|
||||
|
@ -29,14 +37,20 @@ public class Strobe1500 extends BuntiDMXDevice {
|
|||
return setChannelValueByName(CHANNEL_MODE, value);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Transient
|
||||
public final int getSpeed() {
|
||||
return getChannelValueByName(CHANNEL_SPEED);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Transient
|
||||
public final int getIntensity() {
|
||||
return getChannelValueByName(CHANNEL_INTENSITY);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Transient
|
||||
public final int getMode() {
|
||||
return getChannelValueByName(CHANNEL_MODE);
|
||||
}
|
||||
|
@ -59,7 +73,7 @@ public class Strobe1500 extends BuntiDMXDevice {
|
|||
public final String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Strobe1500 ");
|
||||
sb.append(getDeviceId());
|
||||
sb.append(getId());
|
||||
sb.append(", ");
|
||||
sb.append(getDeviceName());
|
||||
sb.append(" [");
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package de.ctdo.bunti.web;
|
||||
|
||||
import de.ctdo.bunti.control.BuntiController;
|
||||
import de.ctdo.bunti.webmodel.DeviceUpdate;
|
||||
import de.ctdo.bunti.webmodel.DeviceUpdates;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/control")
|
||||
public class DeviceControlController {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DeviceControlController.class);
|
||||
private BuntiController controller;
|
||||
|
||||
@Autowired
|
||||
public final void setController(BuntiController controller) {
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/devices", method = RequestMethod.POST)
|
||||
public void setDevices(@RequestBody DeviceUpdates updates) {
|
||||
LOGGER.info("handle PUT /devices" + " request update=" + updates.toString() );
|
||||
|
||||
for (DeviceUpdate update: updates.getUpdates()) {
|
||||
LOGGER.info("Update deviceId=" + update.getDeviceId());
|
||||
controller.updateDeviceData(update.getDeviceId(), update.getOptions());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package de.ctdo.bunti.web;
|
||||
|
||||
import de.ctdo.bunti.dao.BuntiDevicesDAO;
|
||||
import de.ctdo.bunti.model.BuntiDevice;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/devices")
|
||||
public class DevicesController {
|
||||
private BuntiDevicesDAO devicesDAO;
|
||||
|
||||
@Autowired
|
||||
public void setDevicesDAO(BuntiDevicesDAO devicesDAO) {
|
||||
this.devicesDAO = devicesDAO;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "", method = RequestMethod.GET)
|
||||
public @ResponseBody Collection<BuntiDevice> getAll() {
|
||||
return devicesDAO.getAllDevices();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||
public @ResponseBody BuntiDevice getDeviceById(@PathVariable("id") int id) {
|
||||
return devicesDAO.getDeviceById(id);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "", method = RequestMethod.POST)
|
||||
public @ResponseBody BuntiDevice setDevices(@RequestBody BuntiDevice device) {
|
||||
devicesDAO.addDevice(device);
|
||||
return device;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
package de.ctdo.bunti.web;
|
||||
|
||||
import de.ctdo.bunti.control.BuntiController;
|
||||
import de.ctdo.bunti.model.BuntiDevice;
|
||||
import de.ctdo.bunti.webmodel.DeviceUpdate;
|
||||
import de.ctdo.bunti.webmodel.DeviceUpdates;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Validator;
|
||||
import java.util.*;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/control")
|
||||
public class RestController {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RestController.class);
|
||||
private BuntiController controller;
|
||||
|
||||
|
||||
@Autowired
|
||||
public final void setController(BuntiController controller) {
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/devices", method = RequestMethod.GET)
|
||||
public @ResponseBody Collection<BuntiDevice> getAll() {
|
||||
LOGGER.info("handle GET /devices request");
|
||||
return controller.getAllDevices();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/devices/{id}", method = RequestMethod.GET)
|
||||
public @ResponseBody BuntiDevice getDeviceById(@PathVariable("id") int id) {
|
||||
LOGGER.info("handle GET /devices/" + id + " request");
|
||||
return controller.getDeviceById(id);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/devices/{id}", method = RequestMethod.POST)
|
||||
public @ResponseBody BuntiDevice setDeviceById(@PathVariable("id") int id, @RequestBody DeviceUpdate update) {
|
||||
LOGGER.info("handle PUT /devices/" + id + " request update=" + update.toString() );
|
||||
|
||||
|
||||
controller.updateDeviceData(id, update.getOptions());
|
||||
return controller.getDeviceById(id);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/devices", method = RequestMethod.POST)
|
||||
public String setDevices(@RequestBody DeviceUpdates updates) {
|
||||
LOGGER.info("handle PUT /devices" + " request update=" + updates.toString() );
|
||||
|
||||
for (DeviceUpdate update: updates.getUpdates()) {
|
||||
LOGGER.info("Update deviceId=" + update.getDeviceId());
|
||||
|
||||
controller.updateDeviceData(update.getDeviceId(), update.getOptions());
|
||||
}
|
||||
|
||||
return "bla";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package de.ctdo.bunti.web;
|
||||
|
||||
import de.ctdo.bunti.dao.RoomsDAO;
|
||||
import de.ctdo.bunti.model.BuntiDevice;
|
||||
import de.ctdo.bunti.model.Room;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/rooms")
|
||||
public class RoomsController {
|
||||
private RoomsDAO roomsDAO;
|
||||
|
||||
@Autowired
|
||||
public void setRoomsDAO(RoomsDAO roomsDAO) {
|
||||
this.roomsDAO = roomsDAO;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "", method = RequestMethod.GET)
|
||||
public @ResponseBody Collection<Room> getAll() {
|
||||
return roomsDAO.getRooms();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||
public @ResponseBody Room getRoomById(@PathVariable("id") int id) {
|
||||
return roomsDAO.getRoom(id);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{id}/devices", method = RequestMethod.GET)
|
||||
public @ResponseBody
|
||||
List<BuntiDevice> getDevicesFromRoom(@PathVariable("id") int id) {
|
||||
Room room = roomsDAO.getRoom(id);
|
||||
|
||||
if(room != null) {
|
||||
return room.getDevices();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,16 +1,16 @@
|
|||
package de.ctdo.bunti.webmodel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Diese Klasse gibts nur, weil ich es nicht hinbekomme mit Jackson
|
||||
* ein ArrayList<DeviceUpdate> als Parameter im Controller zu verarbeiten.
|
||||
*/
|
||||
public class DeviceUpdates {
|
||||
|
||||
private long timeStamp = 0;
|
||||
|
||||
private List<DeviceUpdate> updates = new ArrayList<DeviceUpdate>();
|
||||
|
||||
|
||||
public List<DeviceUpdate> getUpdates() {
|
||||
return updates;
|
||||
}
|
||||
|
|
|
@ -1,44 +1,43 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc">
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="HSQL">
|
||||
<jdbc:script location="classpath:init.sql" />
|
||||
<jdbc:embedded-database id="dataSource" type="H2">
|
||||
<jdbc:script location="classpath:init_schema.sql" />
|
||||
<jdbc:script location="classpath:init_data.sql" />
|
||||
</jdbc:embedded-database>
|
||||
|
||||
<bean id="hibernateSessionFactory"
|
||||
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
|
||||
<property name="mappingResources">
|
||||
<list>
|
||||
<value>/bunti.hbm.xml</value>
|
||||
</list>
|
||||
</property>
|
||||
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
|
||||
<property name="packagesToScan" value="de.ctdo.bunti.model"/>
|
||||
<property name="hibernateProperties">
|
||||
<props>
|
||||
<prop key="hibernate.dialect">
|
||||
org.hibernate.dialect.HSQLDialect
|
||||
</prop>
|
||||
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
|
||||
<prop key="hibernate.show_sql">true</prop>
|
||||
<!-- <prop key="hibernate.hbm2ddl.auto">create</prop> -->
|
||||
<!--<prop key="hibernate.hbm2ddl.auto">create</prop>-->
|
||||
</props>
|
||||
</property>
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="transactionManager"
|
||||
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
|
||||
<bean id="roomsDAO" class="de.ctdo.bunti.dao.RoomsDAOImpl">
|
||||
<property name="sessionFactory" ref="hibernateSessionFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="roomsDAO" class="de.ctdo.bunti.dao.RoomsDAOImpl">
|
||||
<property name="sessionFactory" ref="hibernateSessionFactory" />
|
||||
</bean>
|
||||
<bean id="devicesDAO" class="de.ctdo.bunti.dao.BuntiDevicesDAOImpl">
|
||||
<property name="sessionFactory" ref="hibernateSessionFactory" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
|
||||
<property name="sessionFactory" ref="hibernateSessionFactory" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
|
||||
<tx:annotation-driven />
|
||||
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping auto-import="true">
|
||||
|
||||
<class name="de.ctdo.bunti.model.Room" table="rooms" >
|
||||
<id name="id" unsaved-value="0">
|
||||
<generator class="native"/>
|
||||
</id>
|
||||
<property name="name"/>
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
|
@ -1,2 +1,2 @@
|
|||
db.driverClassName=org.hsqldb.jdbcDriver
|
||||
db.url=jdbc:hsqldb:mem:buntiserver
|
||||
#db.driverClassName=org.hsqldb.jdbcDriver
|
||||
#db.url=jdbc:hsqldb:mem:buntiserver
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
DROP TABLE DUAL_HIBERNATE_SEQUENCE IF EXISTS
|
||||
DROP TABLE ROOMS IF EXISTS
|
||||
DROP TABLE SEQUENCE IF EXISTS
|
||||
|
||||
|
||||
CREATE MEMORY TABLE SEQUENCE(SEQ_NAME VARCHAR(50) NOT NULL PRIMARY KEY,SEQ_COUNT NUMERIC(38))
|
||||
CREATE MEMORY TABLE ROOMS(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,NAME VARCHAR(255))
|
||||
CREATE MEMORY TABLE DUAL_HIBERNATE_SEQUENCE(ZERO INTEGER)
|
||||
INSERT INTO SEQUENCE VALUES('SEQ_GEN',0)
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
|
||||
insert into rooms (ROOM_ID, floor, roomName, xCord, yCord) values (null, '2. Etage', 'Kueche', '0', '0');
|
||||
insert into rooms (ROOM_ID, floor, roomName, xCord, yCord) values (null, '2. Etage', 'Wohnzimmer', '0', '1');
|
||||
insert into rooms (ROOM_ID, floor, roomName, xCord, yCord) values (null, '2. Etage', 'Werkstatt', '1', '0');
|
||||
insert into rooms (ROOM_ID, floor, roomName, xCord, yCord) values (null, '2. Etage', 'Flur', '1', '1');
|
||||
|
||||
|
||||
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress)
|
||||
values ('Par56Spot',null,'Lampe1',null, 1);
|
||||
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress)
|
||||
values ('Par56Spot',null,'Lampe2',null, 6);
|
||||
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress)
|
||||
values ('Par56Spot',null,'Lampe3',null, 11);
|
||||
insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress)
|
||||
values ('Par56Spot',null,'Lampe4',null, 16);
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
drop table ROOM_BUNTIDEVICE if exists;
|
||||
drop table devices if exists;
|
||||
drop table rooms if exists;
|
||||
|
||||
create table ROOM_BUNTIDEVICE (ROOM_ID integer not null, BUNTIDEVICE_ID int not null,
|
||||
primary key (ROOM_ID, BUNTIDEVICE_ID), unique (BUNTIDEVICE_ID));
|
||||
|
||||
create table devices (DTYPE varchar(31) not null,
|
||||
BUNTIDEVICE_ID integer generated by default as identity (start with 1),
|
||||
deviceName varchar(255),
|
||||
picture varchar(255),
|
||||
startAddress integer,
|
||||
primary key (BUNTIDEVICE_ID));
|
||||
|
||||
create table rooms (ROOM_ID integer generated by default as identity (start with 1),
|
||||
floor varchar(255),
|
||||
roomName varchar(255),
|
||||
xCord integer not null,
|
||||
yCord integer not null,
|
||||
primary key (ROOM_ID));
|
||||
|
||||
alter table ROOM_BUNTIDEVICE add constraint FK96EF8F028BB4B62 foreign key (ROOM_ID) references rooms;
|
||||
alter table ROOM_BUNTIDEVICE add constraint FK96EF8F021E9F392 foreign key (BUNTIDEVICE_ID) references devices;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
#log4j.rootLogger=debug, stdout
|
||||
|
||||
#log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
#log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
|
||||
# Print the date in ISO 8601 format
|
||||
##log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
|
||||
#log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p %c: %m%n
|
||||
|
||||
#log4j.appender.R=org.apache.log4j.RollingFileAppender
|
||||
#log4j.appender.R.File=application.log
|
||||
#log4j.appender.R.MaxFileSize=100KB
|
||||
#log4j.appender.R.MaxBackupIndex=1
|
||||
#log4j.appender.R.layout=org.apache.log4j.PatternLayout
|
||||
#log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
|
|
@ -15,18 +15,18 @@
|
|||
<level value="info" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework.orm">
|
||||
<level value="debug" />
|
||||
</logger>
|
||||
|
||||
|
||||
<logger name="de.ctdo">
|
||||
<level value="debug" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.hibernate">
|
||||
<level value="info" />
|
||||
</logger>
|
||||
|
||||
|
||||
<root>
|
||||
<priority value="debug" />
|
||||
<priority value="info" />
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
|
|
|
@ -12,213 +12,77 @@
|
|||
<link type="text/css" href="<c:url value="/resources/css/smoothness/jquery-ui-1.8.18.custom.css"/>" rel="stylesheet" />
|
||||
<script type="text/javascript" src="<c:url value="/resources/js/jquery-1.7.1.min.js" />"></script>
|
||||
<script type="text/javascript" src="<c:url value="/resources/js/jquery-ui-1.8.18.custom.min.js" />"></script>
|
||||
<script type="text/javascript" src="<c:url value="/resources/js/events.class.js" />"></script>
|
||||
<script type="text/javascript" src="<c:url value="/resources/js/jquery.cookie.js" />"></script>
|
||||
<script type="text/javascript" src="<c:url value="/resources/js/underscore.js" />"></script>
|
||||
<script type="text/javascript" src="<c:url value="/resources/js/backbone-min.js" />"></script>
|
||||
<script type="text/javascript" src="<c:url value="/resources/js/handlebars.js" />"></script>
|
||||
<script type="text/javascript" src="<c:url value="/resources/js/main.js" />"></script>
|
||||
<script type="text/javascript" src="<c:url value="/resources/js/jquery.colorpicker.js" />"></script>
|
||||
<script type="text/javascript" src="<c:url value="/resources/js/jquery.mousewheel.js" />"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
var volumes = $.parseJSON('{"room1":0,"room2":0,"room3":0,"room4":0}');
|
||||
var devices = [
|
||||
{"red":72,"green":69,"blue":255,"startAddress":1,"type":"Par56Spot","deviceId":0,"deviceName":"Par56 Lampe 1","picture":null},
|
||||
{"red":111,"green":222,"blue":23,"startAddress":6,"type":"Par56Spot","deviceId":1,"deviceName":"Par56 Lampe 2","picture":null},
|
||||
{"red":0,"green":0,"blue":0,"startAddress":11,"type":"Par56Spot","deviceId":2,"deviceName":"Par56 Lampe 3","picture":null},
|
||||
{"red":0,"green":0,"blue":0,"startAddress":16,"type":"Par56Spot","deviceId":3,"deviceName":"Par56 Lampe 4","picture":null},
|
||||
{"mode":0,"speed":0,"intensity":0,"startAddress":21,"type":"Strobe1500","deviceId":4,"deviceName":"Stroboskop 1","picture":null},
|
||||
{"red":0,"green":0,"blue":0,"startAddress":508,"type":"Par56Spot","deviceId":5,"deviceName":"Par56 Lampe 5","picture":null}
|
||||
];
|
||||
$(document).ready(
|
||||
function() {
|
||||
<script type="text/javascript" src="<c:url value="/resources/js/models.js" />"></script>
|
||||
<script type="text/javascript" src="<c:url value="/resources/js/views.js" />"></script>
|
||||
|
||||
|
||||
function sendData(data) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: "/control/devices",
|
||||
contentType: "application/json",
|
||||
dataType: "json",
|
||||
data: JSON.stringify(data)
|
||||
});
|
||||
console.log(data);
|
||||
console.log(JSON.stringify(data));
|
||||
}
|
||||
|
||||
var senden = function sendOutAllDevices() {
|
||||
var changedDevs = new Array();
|
||||
for(var i=0;i<devices.length;i++) {
|
||||
if(devices[i].type=="Par56Spot" && devices[i].dirty) {
|
||||
delete devices[i].dirty;
|
||||
var dev = {"deviceId": i, "options":{"red":devices[i].red, "green":devices[i].green, "blue":devices[i].blue}};
|
||||
changedDevs.push(dev);
|
||||
}
|
||||
}
|
||||
if (changedDevs.length > 0) {
|
||||
sendData({"timeStamp": Math.round(new Date().getTime()/1000), "updates": changedDevs});
|
||||
}
|
||||
console.log("set new interval for sending");
|
||||
window.setTimeout(senden, 100);
|
||||
};
|
||||
|
||||
// vielleicht baut man lieber was mit setTimeout und setzt das jeweils neu wenn man daten ändert
|
||||
// das könnte den Browser entlasten, sofern den das 200ms Aufrufen überhaupt stört :D
|
||||
senden();
|
||||
|
||||
$("#slider1").slider({ min: 0, max: 100, slide: function(event, ui) {
|
||||
volumes.room1 = ui.value;
|
||||
dataChanged = true;
|
||||
} });
|
||||
|
||||
$("#slider2").slider({ min: 0, max: 100, slide: function(event, ui) {
|
||||
volumes.room2 = ui.value;
|
||||
dataChanged = true;
|
||||
} });
|
||||
|
||||
$("#slider3").slider({ min: 0, max: 100, slide: function(event, ui) {
|
||||
volumes.room3 = ui.value;
|
||||
dataChanged = true;
|
||||
} });
|
||||
|
||||
$("#slider4").slider({ min: 0, max: 100, slide: function(event, ui) {
|
||||
volumes.room4 = ui.value;
|
||||
dataChanged = true;
|
||||
} });
|
||||
$("#tabs").tabs();
|
||||
$("#v-tabs").tabs().addClass('ui-tabs-vertical');
|
||||
$(".lampel .circle").click(function() {
|
||||
if($(this).hasClass('black')){
|
||||
$(this).removeClass('black');
|
||||
} else {
|
||||
$(this).addClass('black');
|
||||
}
|
||||
});
|
||||
var colorpicker_raum1 = new jQuery.ColorPicker('#colorpicker-raum1', {
|
||||
imagepath: '/resources/images/colorpicker/',
|
||||
change: function(hexcolor) {
|
||||
red = hexcolor.substr(1,2);
|
||||
green = hexcolor.substr(3,2);
|
||||
blue = hexcolor.substr(5,2);
|
||||
$('#par56select option:selected').each(function() {
|
||||
devices[$(this).attr('name')].red = parseInt(red, 16);
|
||||
devices[$(this).attr('name')].green = parseInt(green, 16);
|
||||
devices[$(this).attr('name')].blue = parseInt(blue, 16);
|
||||
devices[$(this).attr('name')].dirty = true;
|
||||
});
|
||||
console.log("data changed");
|
||||
|
||||
}
|
||||
});
|
||||
$.getJSON('/control/devices', function(data) {
|
||||
devices = data;
|
||||
for(var i=0;i<devices.length;i++) {
|
||||
if(devices[i].type=="Par56Spot") {
|
||||
$('#par56select').append("<option name=" + devices[i].deviceId + ">" + devices[i].deviceName + "</option>");
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
$('#par56select').change(function() {
|
||||
$('#par56select option:selected').each(function() {
|
||||
var red = devices[$(this).attr('name')].red.toString(16);
|
||||
if(red.length == 1) {
|
||||
red += red;
|
||||
}
|
||||
var green = devices[$(this).attr('name')].green.toString(16);
|
||||
if(green.length == 1) {
|
||||
green += green;
|
||||
}
|
||||
var blue = devices[$(this).attr('name')].blue.toString(16);
|
||||
if(blue.length == 1) {
|
||||
|
||||
blue += blue;
|
||||
}
|
||||
var hexstring = '#' + red + green + blue;
|
||||
console.log(hexstring);
|
||||
colorpicker_raum1.hex(hexstring);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CTDO Raumsteuerung</h1>
|
||||
<div id="container">
|
||||
<div id="room-tabs">
|
||||
|
||||
<div id="tabs">
|
||||
<ul>
|
||||
<li><a href="#tabs-1">Global</a></li>
|
||||
<li><a href="#tabs-2">Raum 1</a></li>
|
||||
<li><a href="#tabs-3">Raum 2</a></li>
|
||||
<li><a href="#tabs-4">Raum 3</a></li>
|
||||
<li><a href="#tabs-5">Raum 4</a></li>
|
||||
</ul>
|
||||
<div id="tabs-1">
|
||||
|
||||
<div class="buzzer">
|
||||
<span class="circle red">Zu</span>
|
||||
<button>Buzzern</button>
|
||||
</div>
|
||||
<div class="buzzer">
|
||||
<span class="circle green">Auf</span>
|
||||
<button>Buzzern</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="tabs-2">
|
||||
<div id="v-tabs" class="inner-tabs-container">
|
||||
<ul>
|
||||
<li><a href="#v-tabs-1">Licht</a></li>
|
||||
<li><a href="#v-tabs-2">Musik</a></li>
|
||||
<li><a href="#v-tabs-3">Lampel</a></li>
|
||||
</ul>
|
||||
<div id="v-tabs-1">
|
||||
<div id="colorpicker-raum1"></div>
|
||||
<select multiple="multiple" id="par56select">
|
||||
|
||||
</select>
|
||||
</div>
|
||||
<div id="v-tabs-2">
|
||||
<label for="slider1">Lautstärke Raum 1:</label><div id="slider1" class="slider"></div>
|
||||
</div>
|
||||
<div id="v-tabs-3">
|
||||
<div class="lampel">
|
||||
<span class="circle red" title="click to toggle"></span>
|
||||
<span class="circle yellow" title="click to toggle"></span>
|
||||
<span class="circle green" title="click to toggle"></span>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="switch">
|
||||
Raumlicht:<br />
|
||||
<input type="radio" name="raum-1-licht">An <input type="radio" name="raum-1-licht" checked="checked">Aus
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div id="tabs-3">
|
||||
|
||||
<label for="slider2">Lautstärke Raum 2:</label><div id="slider2" class="slider"></div>
|
||||
</div>
|
||||
|
||||
<div id="tabs-4">
|
||||
|
||||
<label for="slider3">Lautstärke Raum 3:</label><div id="slider3" class="slider"></div>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="tabs-5">
|
||||
|
||||
<label for="slider4">Lautstärke Raum 4:</label><div id="slider4" class="slider"></div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/x-handlebars-template" id="room-tabs-template">
|
||||
<ul>
|
||||
{{#each rooms}}
|
||||
<li><a href="#room-tabs-{{roomId}}">{{roomName}}</a></li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
{{#each rooms}}
|
||||
<div id="room-tabs-{{roomId}}">
|
||||
|
||||
</div>
|
||||
{{/each}}
|
||||
</script>
|
||||
<script type="text/x-handlebars-template" id="room-vertical-tabs-template">
|
||||
<div id="room{{roomId}}-vertical-tabs" class="ui-tabs-vertical">
|
||||
<ul>
|
||||
{{#each types}}
|
||||
<li><a href="#room{{roomId}}-vertical-tabs-{{id}}">{{typeName}}</a></li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
{{#each types}}
|
||||
<div id="room{{roomId}}-vertical-tabs-{{id}}">
|
||||
|
||||
<input type="button" value="Get Device 1" id="buttonLampe1" />
|
||||
</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
</script>
|
||||
<script type="text/x-handlebars-template" id="par56-options-template">
|
||||
{{#each devices}}
|
||||
<option name="{{deviceId}}">{{deviceName}}</option>
|
||||
{{/each}}
|
||||
</script>
|
||||
<script type="text/x-handlebars-template" id="buzzer-template">
|
||||
<div class="buzzer">
|
||||
<span class="circle {{color}}">{{text}}</span>
|
||||
<button>Buzzern</button>
|
||||
</div>
|
||||
</script>
|
||||
<script type="text/x-handlebars-template" id="lampel-template">
|
||||
|
||||
<div class="lampel">
|
||||
<span class="circle red" title="click to toggle"></span>
|
||||
<span class="circle yellow" title="click to toggle"></span>
|
||||
<span class="circle green" title="click to toggle"></span>
|
||||
|
||||
</div>
|
||||
</script>
|
||||
<script type="text/x-handlebars-template">
|
||||
|
||||
</script>
|
||||
|
||||
<div id="messages"></div>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
|
@ -0,0 +1,77 @@
|
|||
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
|
||||
<!DOCTYPE html>
|
||||
<%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<title>WebSockets</title>
|
||||
|
||||
<link type="text/css" href="<c:url value="/resources/css/screen.css"/>" rel="stylesheet"/>
|
||||
<link type="text/css" href="<c:url value="/resources/css/styles.css"/>" rel="stylesheet"/>
|
||||
<script type="text/javascript" src="<c:url value="/resources/js/jquery-1.7.1.min.js" />"></script>
|
||||
<script type="text/javascript" src="<c:url value="/resources/js/main.js" />"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function sendData(data) {
|
||||
var time = Math.round(new Date().getTime() / 1000);
|
||||
data = {"timeStamp":time, "updates":data};
|
||||
$.ajax({
|
||||
type:'POST',
|
||||
url:"/control/devices",
|
||||
contentType:"application/json",
|
||||
dataType:"json",
|
||||
data:JSON.stringify(data)
|
||||
});
|
||||
console.log(data);
|
||||
console.log(JSON.stringify(data));
|
||||
}
|
||||
$('#par56 .pink').click(function () {
|
||||
data = [
|
||||
{"deviceId":0, "options":{"red":255, "green":0, "blue":40}},
|
||||
{"deviceId":1, "options":{"red":255, "green":0, "blue":40}},
|
||||
{"deviceId":2, "options":{"red":255, "green":0, "blue":40}},
|
||||
{"deviceId":3, "options":{"red":255, "green":0, "blue":40}}
|
||||
];
|
||||
sendData(data);
|
||||
});
|
||||
$('#par56 .gruen').click(function () {
|
||||
data = [
|
||||
{"deviceId":0, "options":{"red":0, "green":255, "blue":0}},
|
||||
{"deviceId":1, "options":{"red":0, "green":255, "blue":0}},
|
||||
{"deviceId":2, "options":{"red":0, "green":255, "blue":0}},
|
||||
{"deviceId":3, "options":{"red":0, "green":255, "blue":0}}
|
||||
];
|
||||
sendData(data);
|
||||
});
|
||||
$('#par56 .rot').click(function () {
|
||||
data = [
|
||||
{"deviceId":0, "options":{"red":255, "green":0, "blue":0}},
|
||||
{"deviceId":1, "options":{"red":255, "green":0, "blue":0}},
|
||||
{"deviceId":2, "options":{"red":255, "green":0, "blue":0}},
|
||||
{"deviceId":3, "options":{"red":255, "green":0, "blue":0}}
|
||||
];
|
||||
sendData(data);
|
||||
});
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1>CTDO Raumsteuerung</h1>
|
||||
|
||||
<p id="par56">Par56: <br>
|
||||
<button class="pink">Pink</button>
|
||||
<button class="gruen">Grün</button>
|
||||
<button class="rot">Rot</button>
|
||||
</p>
|
||||
<p id="lampel">Lampel:<br>
|
||||
<button class="rota">Rot (an)</button>
|
||||
<button class="gelba">Gelb (an)</button>
|
||||
<button class="gruena">Grün (an)</button>
|
||||
<button class="roto">Rot (aus)</button>
|
||||
<button class="gelbo">Gelb (aus)</button>
|
||||
<button class="grueno">Grün (aus)</button>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
body {
|
||||
font-family: Verdana, Arial, sans-serif;
|
||||
}
|
||||
#tabs {
|
||||
#room-tabs {
|
||||
height: 500px;
|
||||
width: 770px;
|
||||
margin: 0 auto;
|
||||
|
|
|
@ -1,37 +1,38 @@
|
|||
// Backbone.js 0.9.1
|
||||
// Backbone.js 0.9.2
|
||||
|
||||
// (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc.
|
||||
// Backbone may be freely distributed under the MIT license.
|
||||
// For all details and documentation:
|
||||
// http://backbonejs.org
|
||||
(function(){var i=this,r=i.Backbone,s=Array.prototype.slice,t=Array.prototype.splice,g;g="undefined"!==typeof exports?exports:i.Backbone={};g.VERSION="0.9.1";var f=i._;!f&&"undefined"!==typeof require&&(f=require("underscore"));var h=i.jQuery||i.Zepto||i.ender;g.setDomLibrary=function(a){h=a};g.noConflict=function(){i.Backbone=r;return this};g.emulateHTTP=!1;g.emulateJSON=!1;g.Events={on:function(a,b,c){for(var d,a=a.split(/\s+/),e=this._callbacks||(this._callbacks={});d=a.shift();){d=e[d]||(e[d]=
|
||||
{});var f=d.tail||(d.tail=d.next={});f.callback=b;f.context=c;d.tail=f.next={}}return this},off:function(a,b,c){var d,e,f;if(a){if(e=this._callbacks)for(a=a.split(/\s+/);d=a.shift();)if(f=e[d],delete e[d],b&&f)for(;(f=f.next)&&f.next;)if(!(f.callback===b&&(!c||f.context===c)))this.on(d,f.callback,f.context)}else delete this._callbacks;return this},trigger:function(a){var b,c,d,e;if(!(d=this._callbacks))return this;e=d.all;for((a=a.split(/\s+/)).push(null);b=a.shift();)e&&a.push({next:e.next,tail:e.tail,
|
||||
event:b}),(c=d[b])&&a.push({next:c.next,tail:c.tail});for(e=s.call(arguments,1);c=a.pop();){b=c.tail;for(d=c.event?[c.event].concat(e):e;(c=c.next)!==b;)c.callback.apply(c.context||this,d)}return this}};g.Events.bind=g.Events.on;g.Events.unbind=g.Events.off;g.Model=function(a,b){var c;a||(a={});b&&b.parse&&(a=this.parse(a));if(c=j(this,"defaults"))a=f.extend({},c,a);b&&b.collection&&(this.collection=b.collection);this.attributes={};this._escapedAttributes={};this.cid=f.uniqueId("c");if(!this.set(a,
|
||||
{silent:!0}))throw Error("Can't create an invalid model");delete this._changed;this._previousAttributes=f.clone(this.attributes);this.initialize.apply(this,arguments)};f.extend(g.Model.prototype,g.Events,{idAttribute:"id",initialize:function(){},toJSON:function(){return f.clone(this.attributes)},get:function(a){return this.attributes[a]},escape:function(a){var b;if(b=this._escapedAttributes[a])return b;b=this.attributes[a];return this._escapedAttributes[a]=f.escape(null==b?"":""+b)},has:function(a){return null!=
|
||||
this.attributes[a]},set:function(a,b,c){var d,e;f.isObject(a)||null==a?(d=a,c=b):(d={},d[a]=b);c||(c={});if(!d)return this;d instanceof g.Model&&(d=d.attributes);if(c.unset)for(e in d)d[e]=void 0;if(!this._validate(d,c))return!1;this.idAttribute in d&&(this.id=d[this.idAttribute]);var b=this.attributes,k=this._escapedAttributes,n=this._previousAttributes||{},h=this._setting;this._changed||(this._changed={});this._setting=!0;for(e in d)if(a=d[e],f.isEqual(b[e],a)||delete k[e],c.unset?delete b[e]:b[e]=
|
||||
a,this._changing&&!f.isEqual(this._changed[e],a)&&(this.trigger("change:"+e,this,a,c),this._moreChanges=!0),delete this._changed[e],!f.isEqual(n[e],a)||f.has(b,e)!=f.has(n,e))this._changed[e]=a;h||(!c.silent&&this.hasChanged()&&this.change(c),this._setting=!1);return this},unset:function(a,b){(b||(b={})).unset=!0;return this.set(a,null,b)},clear:function(a){(a||(a={})).unset=!0;return this.set(f.clone(this.attributes),a)},fetch:function(a){var a=a?f.clone(a):{},b=this,c=a.success;a.success=function(d,
|
||||
e,f){if(!b.set(b.parse(d,f),a))return!1;c&&c(b,d)};a.error=g.wrapError(a.error,b,a);return(this.sync||g.sync).call(this,"read",this,a)},save:function(a,b,c){var d,e;f.isObject(a)||null==a?(d=a,c=b):(d={},d[a]=b);c=c?f.clone(c):{};c.wait&&(e=f.clone(this.attributes));a=f.extend({},c,{silent:!0});if(d&&!this.set(d,c.wait?a:c))return!1;var k=this,h=c.success;c.success=function(a,b,e){b=k.parse(a,e);c.wait&&(b=f.extend(d||{},b));if(!k.set(b,c))return!1;h?h(k,a):k.trigger("sync",k,a,c)};c.error=g.wrapError(c.error,
|
||||
k,c);b=this.isNew()?"create":"update";b=(this.sync||g.sync).call(this,b,this,c);c.wait&&this.set(e,a);return b},destroy:function(a){var a=a?f.clone(a):{},b=this,c=a.success,d=function(){b.trigger("destroy",b,b.collection,a)};if(this.isNew())return d();a.success=function(e){a.wait&&d();c?c(b,e):b.trigger("sync",b,e,a)};a.error=g.wrapError(a.error,b,a);var e=(this.sync||g.sync).call(this,"delete",this,a);a.wait||d();return e},url:function(){var a=j(this.collection,"url")||j(this,"urlRoot")||o();return this.isNew()?
|
||||
a:a+("/"==a.charAt(a.length-1)?"":"/")+encodeURIComponent(this.id)},parse:function(a){return a},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return null==this.id},change:function(a){if(this._changing||!this.hasChanged())return this;this._moreChanges=this._changing=!0;for(var b in this._changed)this.trigger("change:"+b,this,this._changed[b],a);for(;this._moreChanges;)this._moreChanges=!1,this.trigger("change",this,a);this._previousAttributes=f.clone(this.attributes);
|
||||
delete this._changed;this._changing=!1;return this},hasChanged:function(a){return!arguments.length?!f.isEmpty(this._changed):this._changed&&f.has(this._changed,a)},changedAttributes:function(a){if(!a)return this.hasChanged()?f.clone(this._changed):!1;var b,c=!1,d=this._previousAttributes,e;for(e in a)if(!f.isEqual(d[e],b=a[e]))(c||(c={}))[e]=b;return c},previous:function(a){return!arguments.length||!this._previousAttributes?null:this._previousAttributes[a]},previousAttributes:function(){return f.clone(this._previousAttributes)},
|
||||
isValid:function(){return!this.validate(this.attributes)},_validate:function(a,b){if(b.silent||!this.validate)return!0;var a=f.extend({},this.attributes,a),c=this.validate(a,b);if(!c)return!0;b&&b.error?b.error(this,c,b):this.trigger("error",this,c,b);return!1}});g.Collection=function(a,b){b||(b={});b.comparator&&(this.comparator=b.comparator);this._reset();this.initialize.apply(this,arguments);a&&this.reset(a,{silent:!0,parse:b.parse})};f.extend(g.Collection.prototype,g.Events,{model:g.Model,initialize:function(){},
|
||||
toJSON:function(){return this.map(function(a){return a.toJSON()})},add:function(a,b){var c,d,e,g,h,i={},j={};b||(b={});a=f.isArray(a)?a.slice():[a];for(c=0,d=a.length;c<d;c++){if(!(e=a[c]=this._prepareModel(a[c],b)))throw Error("Can't add an invalid model to a collection");if(i[g=e.cid]||this._byCid[g]||null!=(h=e.id)&&(j[h]||this._byId[h]))throw Error("Can't add the same model to a collection twice");i[g]=j[h]=e}for(c=0;c<d;c++)(e=a[c]).on("all",this._onModelEvent,this),this._byCid[e.cid]=e,null!=
|
||||
e.id&&(this._byId[e.id]=e);this.length+=d;t.apply(this.models,[null!=b.at?b.at:this.models.length,0].concat(a));this.comparator&&this.sort({silent:!0});if(b.silent)return this;for(c=0,d=this.models.length;c<d;c++)if(i[(e=this.models[c]).cid])b.index=c,e.trigger("add",e,this,b);return this},remove:function(a,b){var c,d,e,g;b||(b={});a=f.isArray(a)?a.slice():[a];for(c=0,d=a.length;c<d;c++)if(g=this.getByCid(a[c])||this.get(a[c]))delete this._byId[g.id],delete this._byCid[g.cid],e=this.indexOf(g),this.models.splice(e,
|
||||
1),this.length--,b.silent||(b.index=e,g.trigger("remove",g,this,b)),this._removeReference(g);return this},get:function(a){return null==a?null:this._byId[null!=a.id?a.id:a]},getByCid:function(a){return a&&this._byCid[a.cid||a]},at:function(a){return this.models[a]},sort:function(a){a||(a={});if(!this.comparator)throw Error("Cannot sort a set without a comparator");var b=f.bind(this.comparator,this);1==this.comparator.length?this.models=this.sortBy(b):this.models.sort(b);a.silent||this.trigger("reset",
|
||||
this,a);return this},pluck:function(a){return f.map(this.models,function(b){return b.get(a)})},reset:function(a,b){a||(a=[]);b||(b={});for(var c=0,d=this.models.length;c<d;c++)this._removeReference(this.models[c]);this._reset();this.add(a,{silent:!0,parse:b.parse});b.silent||this.trigger("reset",this,b);return this},fetch:function(a){a=a?f.clone(a):{};void 0===a.parse&&(a.parse=!0);var b=this,c=a.success;a.success=function(d,e,f){b[a.add?"add":"reset"](b.parse(d,f),a);c&&c(b,d)};a.error=g.wrapError(a.error,
|
||||
b,a);return(this.sync||g.sync).call(this,"read",this,a)},create:function(a,b){var c=this,b=b?f.clone(b):{},a=this._prepareModel(a,b);if(!a)return!1;b.wait||c.add(a,b);var d=b.success;b.success=function(e,f){b.wait&&c.add(e,b);d?d(e,f):e.trigger("sync",a,f,b)};a.save(null,b);return a},parse:function(a){return a},chain:function(){return f(this.models).chain()},_reset:function(){this.length=0;this.models=[];this._byId={};this._byCid={}},_prepareModel:function(a,b){a instanceof g.Model?a.collection||
|
||||
(a.collection=this):(b.collection=this,a=new this.model(a,b),a._validate(a.attributes,b)||(a=!1));return a},_removeReference:function(a){this==a.collection&&delete a.collection;a.off("all",this._onModelEvent,this)},_onModelEvent:function(a,b,c,d){("add"==a||"remove"==a)&&c!=this||("destroy"==a&&this.remove(b,d),b&&a==="change:"+b.idAttribute&&(delete this._byId[b.previous(b.idAttribute)],this._byId[b.id]=b),this.trigger.apply(this,arguments))}});f.each("forEach,each,map,reduce,reduceRight,find,detect,filter,select,reject,every,all,some,any,include,contains,invoke,max,min,sortBy,sortedIndex,toArray,size,first,initial,rest,last,without,indexOf,shuffle,lastIndexOf,isEmpty,groupBy".split(","),
|
||||
function(a){g.Collection.prototype[a]=function(){return f[a].apply(f,[this.models].concat(f.toArray(arguments)))}});g.Router=function(a){a||(a={});a.routes&&(this.routes=a.routes);this._bindRoutes();this.initialize.apply(this,arguments)};var u=/:\w+/g,v=/\*\w+/g,w=/[-[\]{}()+?.,\\^$|#\s]/g;f.extend(g.Router.prototype,g.Events,{initialize:function(){},route:function(a,b,c){g.history||(g.history=new g.History);f.isRegExp(a)||(a=this._routeToRegExp(a));c||(c=this[b]);g.history.route(a,f.bind(function(d){d=
|
||||
this._extractParameters(a,d);c&&c.apply(this,d);this.trigger.apply(this,["route:"+b].concat(d));g.history.trigger("route",this,b,d)},this));return this},navigate:function(a,b){g.history.navigate(a,b)},_bindRoutes:function(){if(this.routes){var a=[],b;for(b in this.routes)a.unshift([b,this.routes[b]]);b=0;for(var c=a.length;b<c;b++)this.route(a[b][0],a[b][1],this[a[b][1]])}},_routeToRegExp:function(a){a=a.replace(w,"\\$&").replace(u,"([^/]+)").replace(v,"(.*?)");return RegExp("^"+a+"$")},_extractParameters:function(a,
|
||||
b){return a.exec(b).slice(1)}});g.History=function(){this.handlers=[];f.bindAll(this,"checkUrl")};var m=/^[#\/]/,x=/msie [\w.]+/,l=!1;f.extend(g.History.prototype,g.Events,{interval:50,getFragment:function(a,b){if(null==a)if(this._hasPushState||b){var a=window.location.pathname,c=window.location.search;c&&(a+=c)}else a=window.location.hash;a=decodeURIComponent(a);a.indexOf(this.options.root)||(a=a.substr(this.options.root.length));return a.replace(m,"")},start:function(a){if(l)throw Error("Backbone.history has already been started");
|
||||
this.options=f.extend({},{root:"/"},this.options,a);this._wantsHashChange=!1!==this.options.hashChange;this._wantsPushState=!!this.options.pushState;this._hasPushState=!(!this.options.pushState||!window.history||!window.history.pushState);var a=this.getFragment(),b=document.documentMode;if(b=x.exec(navigator.userAgent.toLowerCase())&&(!b||7>=b))this.iframe=h('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo("body")[0].contentWindow,this.navigate(a);this._hasPushState?h(window).bind("popstate",
|
||||
this.checkUrl):this._wantsHashChange&&"onhashchange"in window&&!b?h(window).bind("hashchange",this.checkUrl):this._wantsHashChange&&(this._checkUrlInterval=setInterval(this.checkUrl,this.interval));this.fragment=a;l=!0;a=window.location;b=a.pathname==this.options.root;if(this._wantsHashChange&&this._wantsPushState&&!this._hasPushState&&!b)return this.fragment=this.getFragment(null,!0),window.location.replace(this.options.root+"#"+this.fragment),!0;this._wantsPushState&&this._hasPushState&&b&&a.hash&&
|
||||
(this.fragment=a.hash.replace(m,""),window.history.replaceState({},document.title,a.protocol+"//"+a.host+this.options.root+this.fragment));if(!this.options.silent)return this.loadUrl()},stop:function(){h(window).unbind("popstate",this.checkUrl).unbind("hashchange",this.checkUrl);clearInterval(this._checkUrlInterval);l=!1},route:function(a,b){this.handlers.unshift({route:a,callback:b})},checkUrl:function(){var a=this.getFragment();a==this.fragment&&this.iframe&&(a=this.getFragment(this.iframe.location.hash));
|
||||
if(a==this.fragment||a==decodeURIComponent(this.fragment))return!1;this.iframe&&this.navigate(a);this.loadUrl()||this.loadUrl(window.location.hash)},loadUrl:function(a){var b=this.fragment=this.getFragment(a);return f.any(this.handlers,function(a){if(a.route.test(b))return a.callback(b),!0})},navigate:function(a,b){if(!l)return!1;if(!b||!0===b)b={trigger:b};var c=(a||"").replace(m,"");this.fragment==c||this.fragment==decodeURIComponent(c)||(this._hasPushState?(0!=c.indexOf(this.options.root)&&(c=
|
||||
this.options.root+c),this.fragment=c,window.history[b.replace?"replaceState":"pushState"]({},document.title,c)):this._wantsHashChange?(this.fragment=c,this._updateHash(window.location,c,b.replace),this.iframe&&c!=this.getFragment(this.iframe.location.hash)&&(b.replace||this.iframe.document.open().close(),this._updateHash(this.iframe.location,c,b.replace))):window.location.assign(this.options.root+a),b.trigger&&this.loadUrl(a))},_updateHash:function(a,b,c){c?a.replace(a.toString().replace(/(javascript:|#).*$/,
|
||||
"")+"#"+b):a.hash=b}});g.View=function(a){this.cid=f.uniqueId("view");this._configure(a||{});this._ensureElement();this.initialize.apply(this,arguments);this.delegateEvents()};var y=/^(\S+)\s*(.*)$/,p="model,collection,el,id,attributes,className,tagName".split(",");f.extend(g.View.prototype,g.Events,{tagName:"div",$:function(a){return this.$el.find(a)},initialize:function(){},render:function(){return this},remove:function(){this.$el.remove();return this},make:function(a,b,c){a=document.createElement(a);
|
||||
b&&h(a).attr(b);c&&h(a).html(c);return a},setElement:function(a,b){this.$el=h(a);this.el=this.$el[0];!1!==b&&this.delegateEvents();return this},delegateEvents:function(a){if(a||(a=j(this,"events"))){this.undelegateEvents();for(var b in a){var c=a[b];f.isFunction(c)||(c=this[a[b]]);if(!c)throw Error('Event "'+a[b]+'" does not exist');var d=b.match(y),e=d[1],d=d[2],c=f.bind(c,this),e=e+(".delegateEvents"+this.cid);""===d?this.$el.bind(e,c):this.$el.delegate(d,e,c)}}},undelegateEvents:function(){this.$el.unbind(".delegateEvents"+
|
||||
this.cid)},_configure:function(a){this.options&&(a=f.extend({},this.options,a));for(var b=0,c=p.length;b<c;b++){var d=p[b];a[d]&&(this[d]=a[d])}this.options=a},_ensureElement:function(){if(this.el)this.setElement(this.el,!1);else{var a=j(this,"attributes")||{};this.id&&(a.id=this.id);this.className&&(a["class"]=this.className);this.setElement(this.make(this.tagName,a),!1)}}});g.Model.extend=g.Collection.extend=g.Router.extend=g.View.extend=function(a,b){var c=z(this,a,b);c.extend=this.extend;return c};
|
||||
var A={create:"POST",update:"PUT","delete":"DELETE",read:"GET"};g.sync=function(a,b,c){var d=A[a],e={type:d,dataType:"json"};c.url||(e.url=j(b,"url")||o());if(!c.data&&b&&("create"==a||"update"==a))e.contentType="application/json",e.data=JSON.stringify(b.toJSON());g.emulateJSON&&(e.contentType="application/x-www-form-urlencoded",e.data=e.data?{model:e.data}:{});if(g.emulateHTTP&&("PUT"===d||"DELETE"===d))g.emulateJSON&&(e.data._method=d),e.type="POST",e.beforeSend=function(a){a.setRequestHeader("X-HTTP-Method-Override",
|
||||
d)};"GET"!==e.type&&!g.emulateJSON&&(e.processData=!1);return h.ajax(f.extend(e,c))};g.wrapError=function(a,b,c){return function(d,e){e=d===b?e:d;a?a(b,e,c):b.trigger("error",b,e,c)}};var q=function(){},z=function(a,b,c){var d;d=b&&b.hasOwnProperty("constructor")?b.constructor:function(){a.apply(this,arguments)};f.extend(d,a);q.prototype=a.prototype;d.prototype=new q;b&&f.extend(d.prototype,b);c&&f.extend(d,c);d.prototype.constructor=d;d.__super__=a.prototype;return d},j=function(a,b){return!a||!a[b]?
|
||||
null:f.isFunction(a[b])?a[b]():a[b]},o=function(){throw Error('A "url" property or function must be specified');}}).call(this);
|
||||
(function(){var l=this,y=l.Backbone,z=Array.prototype.slice,A=Array.prototype.splice,g;g="undefined"!==typeof exports?exports:l.Backbone={};g.VERSION="0.9.2";var f=l._;!f&&"undefined"!==typeof require&&(f=require("underscore"));var i=l.jQuery||l.Zepto||l.ender;g.setDomLibrary=function(a){i=a};g.noConflict=function(){l.Backbone=y;return this};g.emulateHTTP=!1;g.emulateJSON=!1;var p=/\s+/,k=g.Events={on:function(a,b,c){var d,e,f,g,j;if(!b)return this;a=a.split(p);for(d=this._callbacks||(this._callbacks=
|
||||
{});e=a.shift();)f=(j=d[e])?j.tail:{},f.next=g={},f.context=c,f.callback=b,d[e]={tail:g,next:j?j.next:f};return this},off:function(a,b,c){var d,e,h,g,j,q;if(e=this._callbacks){if(!a&&!b&&!c)return delete this._callbacks,this;for(a=a?a.split(p):f.keys(e);d=a.shift();)if(h=e[d],delete e[d],h&&(b||c))for(g=h.tail;(h=h.next)!==g;)if(j=h.callback,q=h.context,b&&j!==b||c&&q!==c)this.on(d,j,q);return this}},trigger:function(a){var b,c,d,e,f,g;if(!(d=this._callbacks))return this;f=d.all;a=a.split(p);for(g=
|
||||
z.call(arguments,1);b=a.shift();){if(c=d[b])for(e=c.tail;(c=c.next)!==e;)c.callback.apply(c.context||this,g);if(c=f){e=c.tail;for(b=[b].concat(g);(c=c.next)!==e;)c.callback.apply(c.context||this,b)}}return this}};k.bind=k.on;k.unbind=k.off;var o=g.Model=function(a,b){var c;a||(a={});b&&b.parse&&(a=this.parse(a));if(c=n(this,"defaults"))a=f.extend({},c,a);b&&b.collection&&(this.collection=b.collection);this.attributes={};this._escapedAttributes={};this.cid=f.uniqueId("c");this.changed={};this._silent=
|
||||
{};this._pending={};this.set(a,{silent:!0});this.changed={};this._silent={};this._pending={};this._previousAttributes=f.clone(this.attributes);this.initialize.apply(this,arguments)};f.extend(o.prototype,k,{changed:null,_silent:null,_pending:null,idAttribute:"id",initialize:function(){},toJSON:function(){return f.clone(this.attributes)},get:function(a){return this.attributes[a]},escape:function(a){var b;if(b=this._escapedAttributes[a])return b;b=this.get(a);return this._escapedAttributes[a]=f.escape(null==
|
||||
b?"":""+b)},has:function(a){return null!=this.get(a)},set:function(a,b,c){var d,e;f.isObject(a)||null==a?(d=a,c=b):(d={},d[a]=b);c||(c={});if(!d)return this;d instanceof o&&(d=d.attributes);if(c.unset)for(e in d)d[e]=void 0;if(!this._validate(d,c))return!1;this.idAttribute in d&&(this.id=d[this.idAttribute]);var b=c.changes={},h=this.attributes,g=this._escapedAttributes,j=this._previousAttributes||{};for(e in d){a=d[e];if(!f.isEqual(h[e],a)||c.unset&&f.has(h,e))delete g[e],(c.silent?this._silent:
|
||||
b)[e]=!0;c.unset?delete h[e]:h[e]=a;!f.isEqual(j[e],a)||f.has(h,e)!=f.has(j,e)?(this.changed[e]=a,c.silent||(this._pending[e]=!0)):(delete this.changed[e],delete this._pending[e])}c.silent||this.change(c);return this},unset:function(a,b){(b||(b={})).unset=!0;return this.set(a,null,b)},clear:function(a){(a||(a={})).unset=!0;return this.set(f.clone(this.attributes),a)},fetch:function(a){var a=a?f.clone(a):{},b=this,c=a.success;a.success=function(d,e,f){if(!b.set(b.parse(d,f),a))return!1;c&&c(b,d)};
|
||||
a.error=g.wrapError(a.error,b,a);return(this.sync||g.sync).call(this,"read",this,a)},save:function(a,b,c){var d,e;f.isObject(a)||null==a?(d=a,c=b):(d={},d[a]=b);c=c?f.clone(c):{};if(c.wait){if(!this._validate(d,c))return!1;e=f.clone(this.attributes)}a=f.extend({},c,{silent:!0});if(d&&!this.set(d,c.wait?a:c))return!1;var h=this,i=c.success;c.success=function(a,b,e){b=h.parse(a,e);if(c.wait){delete c.wait;b=f.extend(d||{},b)}if(!h.set(b,c))return false;i?i(h,a):h.trigger("sync",h,a,c)};c.error=g.wrapError(c.error,
|
||||
h,c);b=this.isNew()?"create":"update";b=(this.sync||g.sync).call(this,b,this,c);c.wait&&this.set(e,a);return b},destroy:function(a){var a=a?f.clone(a):{},b=this,c=a.success,d=function(){b.trigger("destroy",b,b.collection,a)};if(this.isNew())return d(),!1;a.success=function(e){a.wait&&d();c?c(b,e):b.trigger("sync",b,e,a)};a.error=g.wrapError(a.error,b,a);var e=(this.sync||g.sync).call(this,"delete",this,a);a.wait||d();return e},url:function(){var a=n(this,"urlRoot")||n(this.collection,"url")||t();
|
||||
return this.isNew()?a:a+("/"==a.charAt(a.length-1)?"":"/")+encodeURIComponent(this.id)},parse:function(a){return a},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return null==this.id},change:function(a){a||(a={});var b=this._changing;this._changing=!0;for(var c in this._silent)this._pending[c]=!0;var d=f.extend({},a.changes,this._silent);this._silent={};for(c in d)this.trigger("change:"+c,this,this.get(c),a);if(b)return this;for(;!f.isEmpty(this._pending);){this._pending=
|
||||
{};this.trigger("change",this,a);for(c in this.changed)!this._pending[c]&&!this._silent[c]&&delete this.changed[c];this._previousAttributes=f.clone(this.attributes)}this._changing=!1;return this},hasChanged:function(a){return!arguments.length?!f.isEmpty(this.changed):f.has(this.changed,a)},changedAttributes:function(a){if(!a)return this.hasChanged()?f.clone(this.changed):!1;var b,c=!1,d=this._previousAttributes,e;for(e in a)if(!f.isEqual(d[e],b=a[e]))(c||(c={}))[e]=b;return c},previous:function(a){return!arguments.length||
|
||||
!this._previousAttributes?null:this._previousAttributes[a]},previousAttributes:function(){return f.clone(this._previousAttributes)},isValid:function(){return!this.validate(this.attributes)},_validate:function(a,b){if(b.silent||!this.validate)return!0;var a=f.extend({},this.attributes,a),c=this.validate(a,b);if(!c)return!0;b&&b.error?b.error(this,c,b):this.trigger("error",this,c,b);return!1}});var r=g.Collection=function(a,b){b||(b={});b.model&&(this.model=b.model);b.comparator&&(this.comparator=b.comparator);
|
||||
this._reset();this.initialize.apply(this,arguments);a&&this.reset(a,{silent:!0,parse:b.parse})};f.extend(r.prototype,k,{model:o,initialize:function(){},toJSON:function(a){return this.map(function(b){return b.toJSON(a)})},add:function(a,b){var c,d,e,g,i,j={},k={},l=[];b||(b={});a=f.isArray(a)?a.slice():[a];c=0;for(d=a.length;c<d;c++){if(!(e=a[c]=this._prepareModel(a[c],b)))throw Error("Can't add an invalid model to a collection");g=e.cid;i=e.id;j[g]||this._byCid[g]||null!=i&&(k[i]||this._byId[i])?
|
||||
l.push(c):j[g]=k[i]=e}for(c=l.length;c--;)a.splice(l[c],1);c=0;for(d=a.length;c<d;c++)(e=a[c]).on("all",this._onModelEvent,this),this._byCid[e.cid]=e,null!=e.id&&(this._byId[e.id]=e);this.length+=d;A.apply(this.models,[null!=b.at?b.at:this.models.length,0].concat(a));this.comparator&&this.sort({silent:!0});if(b.silent)return this;c=0;for(d=this.models.length;c<d;c++)if(j[(e=this.models[c]).cid])b.index=c,e.trigger("add",e,this,b);return this},remove:function(a,b){var c,d,e,g;b||(b={});a=f.isArray(a)?
|
||||
a.slice():[a];c=0;for(d=a.length;c<d;c++)if(g=this.getByCid(a[c])||this.get(a[c]))delete this._byId[g.id],delete this._byCid[g.cid],e=this.indexOf(g),this.models.splice(e,1),this.length--,b.silent||(b.index=e,g.trigger("remove",g,this,b)),this._removeReference(g);return this},push:function(a,b){a=this._prepareModel(a,b);this.add(a,b);return a},pop:function(a){var b=this.at(this.length-1);this.remove(b,a);return b},unshift:function(a,b){a=this._prepareModel(a,b);this.add(a,f.extend({at:0},b));return a},
|
||||
shift:function(a){var b=this.at(0);this.remove(b,a);return b},get:function(a){return null==a?void 0:this._byId[null!=a.id?a.id:a]},getByCid:function(a){return a&&this._byCid[a.cid||a]},at:function(a){return this.models[a]},where:function(a){return f.isEmpty(a)?[]:this.filter(function(b){for(var c in a)if(a[c]!==b.get(c))return!1;return!0})},sort:function(a){a||(a={});if(!this.comparator)throw Error("Cannot sort a set without a comparator");var b=f.bind(this.comparator,this);1==this.comparator.length?
|
||||
this.models=this.sortBy(b):this.models.sort(b);a.silent||this.trigger("reset",this,a);return this},pluck:function(a){return f.map(this.models,function(b){return b.get(a)})},reset:function(a,b){a||(a=[]);b||(b={});for(var c=0,d=this.models.length;c<d;c++)this._removeReference(this.models[c]);this._reset();this.add(a,f.extend({silent:!0},b));b.silent||this.trigger("reset",this,b);return this},fetch:function(a){a=a?f.clone(a):{};void 0===a.parse&&(a.parse=!0);var b=this,c=a.success;a.success=function(d,
|
||||
e,f){b[a.add?"add":"reset"](b.parse(d,f),a);c&&c(b,d)};a.error=g.wrapError(a.error,b,a);return(this.sync||g.sync).call(this,"read",this,a)},create:function(a,b){var c=this,b=b?f.clone(b):{},a=this._prepareModel(a,b);if(!a)return!1;b.wait||c.add(a,b);var d=b.success;b.success=function(e,f){b.wait&&c.add(e,b);d?d(e,f):e.trigger("sync",a,f,b)};a.save(null,b);return a},parse:function(a){return a},chain:function(){return f(this.models).chain()},_reset:function(){this.length=0;this.models=[];this._byId=
|
||||
{};this._byCid={}},_prepareModel:function(a,b){b||(b={});a instanceof o?a.collection||(a.collection=this):(b.collection=this,a=new this.model(a,b),a._validate(a.attributes,b)||(a=!1));return a},_removeReference:function(a){this==a.collection&&delete a.collection;a.off("all",this._onModelEvent,this)},_onModelEvent:function(a,b,c,d){("add"==a||"remove"==a)&&c!=this||("destroy"==a&&this.remove(b,d),b&&a==="change:"+b.idAttribute&&(delete this._byId[b.previous(b.idAttribute)],this._byId[b.id]=b),this.trigger.apply(this,
|
||||
arguments))}});f.each("forEach,each,map,reduce,reduceRight,find,detect,filter,select,reject,every,all,some,any,include,contains,invoke,max,min,sortBy,sortedIndex,toArray,size,first,initial,rest,last,without,indexOf,shuffle,lastIndexOf,isEmpty,groupBy".split(","),function(a){r.prototype[a]=function(){return f[a].apply(f,[this.models].concat(f.toArray(arguments)))}});var u=g.Router=function(a){a||(a={});a.routes&&(this.routes=a.routes);this._bindRoutes();this.initialize.apply(this,arguments)},B=/:\w+/g,
|
||||
C=/\*\w+/g,D=/[-[\]{}()+?.,\\^$|#\s]/g;f.extend(u.prototype,k,{initialize:function(){},route:function(a,b,c){g.history||(g.history=new m);f.isRegExp(a)||(a=this._routeToRegExp(a));c||(c=this[b]);g.history.route(a,f.bind(function(d){d=this._extractParameters(a,d);c&&c.apply(this,d);this.trigger.apply(this,["route:"+b].concat(d));g.history.trigger("route",this,b,d)},this));return this},navigate:function(a,b){g.history.navigate(a,b)},_bindRoutes:function(){if(this.routes){var a=[],b;for(b in this.routes)a.unshift([b,
|
||||
this.routes[b]]);b=0;for(var c=a.length;b<c;b++)this.route(a[b][0],a[b][1],this[a[b][1]])}},_routeToRegExp:function(a){a=a.replace(D,"\\$&").replace(B,"([^/]+)").replace(C,"(.*?)");return RegExp("^"+a+"$")},_extractParameters:function(a,b){return a.exec(b).slice(1)}});var m=g.History=function(){this.handlers=[];f.bindAll(this,"checkUrl")},s=/^[#\/]/,E=/msie [\w.]+/;m.started=!1;f.extend(m.prototype,k,{interval:50,getHash:function(a){return(a=(a?a.location:window.location).href.match(/#(.*)$/))?a[1]:
|
||||
""},getFragment:function(a,b){if(null==a)if(this._hasPushState||b){var a=window.location.pathname,c=window.location.search;c&&(a+=c)}else a=this.getHash();a.indexOf(this.options.root)||(a=a.substr(this.options.root.length));return a.replace(s,"")},start:function(a){if(m.started)throw Error("Backbone.history has already been started");m.started=!0;this.options=f.extend({},{root:"/"},this.options,a);this._wantsHashChange=!1!==this.options.hashChange;this._wantsPushState=!!this.options.pushState;this._hasPushState=
|
||||
!(!this.options.pushState||!window.history||!window.history.pushState);var a=this.getFragment(),b=document.documentMode;if(b=E.exec(navigator.userAgent.toLowerCase())&&(!b||7>=b))this.iframe=i('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo("body")[0].contentWindow,this.navigate(a);this._hasPushState?i(window).bind("popstate",this.checkUrl):this._wantsHashChange&&"onhashchange"in window&&!b?i(window).bind("hashchange",this.checkUrl):this._wantsHashChange&&(this._checkUrlInterval=setInterval(this.checkUrl,
|
||||
this.interval));this.fragment=a;a=window.location;b=a.pathname==this.options.root;if(this._wantsHashChange&&this._wantsPushState&&!this._hasPushState&&!b)return this.fragment=this.getFragment(null,!0),window.location.replace(this.options.root+"#"+this.fragment),!0;this._wantsPushState&&this._hasPushState&&b&&a.hash&&(this.fragment=this.getHash().replace(s,""),window.history.replaceState({},document.title,a.protocol+"//"+a.host+this.options.root+this.fragment));if(!this.options.silent)return this.loadUrl()},
|
||||
stop:function(){i(window).unbind("popstate",this.checkUrl).unbind("hashchange",this.checkUrl);clearInterval(this._checkUrlInterval);m.started=!1},route:function(a,b){this.handlers.unshift({route:a,callback:b})},checkUrl:function(){var a=this.getFragment();a==this.fragment&&this.iframe&&(a=this.getFragment(this.getHash(this.iframe)));if(a==this.fragment)return!1;this.iframe&&this.navigate(a);this.loadUrl()||this.loadUrl(this.getHash())},loadUrl:function(a){var b=this.fragment=this.getFragment(a);return f.any(this.handlers,
|
||||
function(a){if(a.route.test(b))return a.callback(b),!0})},navigate:function(a,b){if(!m.started)return!1;if(!b||!0===b)b={trigger:b};var c=(a||"").replace(s,"");this.fragment!=c&&(this._hasPushState?(0!=c.indexOf(this.options.root)&&(c=this.options.root+c),this.fragment=c,window.history[b.replace?"replaceState":"pushState"]({},document.title,c)):this._wantsHashChange?(this.fragment=c,this._updateHash(window.location,c,b.replace),this.iframe&&c!=this.getFragment(this.getHash(this.iframe))&&(b.replace||
|
||||
this.iframe.document.open().close(),this._updateHash(this.iframe.location,c,b.replace))):window.location.assign(this.options.root+a),b.trigger&&this.loadUrl(a))},_updateHash:function(a,b,c){c?a.replace(a.toString().replace(/(javascript:|#).*$/,"")+"#"+b):a.hash=b}});var v=g.View=function(a){this.cid=f.uniqueId("view");this._configure(a||{});this._ensureElement();this.initialize.apply(this,arguments);this.delegateEvents()},F=/^(\S+)\s*(.*)$/,w="model,collection,el,id,attributes,className,tagName".split(",");
|
||||
f.extend(v.prototype,k,{tagName:"div",$:function(a){return this.$el.find(a)},initialize:function(){},render:function(){return this},remove:function(){this.$el.remove();return this},make:function(a,b,c){a=document.createElement(a);b&&i(a).attr(b);c&&i(a).html(c);return a},setElement:function(a,b){this.$el&&this.undelegateEvents();this.$el=a instanceof i?a:i(a);this.el=this.$el[0];!1!==b&&this.delegateEvents();return this},delegateEvents:function(a){if(a||(a=n(this,"events"))){this.undelegateEvents();
|
||||
for(var b in a){var c=a[b];f.isFunction(c)||(c=this[a[b]]);if(!c)throw Error('Method "'+a[b]+'" does not exist');var d=b.match(F),e=d[1],d=d[2],c=f.bind(c,this),e=e+(".delegateEvents"+this.cid);""===d?this.$el.bind(e,c):this.$el.delegate(d,e,c)}}},undelegateEvents:function(){this.$el.unbind(".delegateEvents"+this.cid)},_configure:function(a){this.options&&(a=f.extend({},this.options,a));for(var b=0,c=w.length;b<c;b++){var d=w[b];a[d]&&(this[d]=a[d])}this.options=a},_ensureElement:function(){if(this.el)this.setElement(this.el,
|
||||
!1);else{var a=n(this,"attributes")||{};this.id&&(a.id=this.id);this.className&&(a["class"]=this.className);this.setElement(this.make(this.tagName,a),!1)}}});o.extend=r.extend=u.extend=v.extend=function(a,b){var c=G(this,a,b);c.extend=this.extend;return c};var H={create:"POST",update:"PUT","delete":"DELETE",read:"GET"};g.sync=function(a,b,c){var d=H[a];c||(c={});var e={type:d,dataType:"json"};c.url||(e.url=n(b,"url")||t());if(!c.data&&b&&("create"==a||"update"==a))e.contentType="application/json",
|
||||
e.data=JSON.stringify(b.toJSON());g.emulateJSON&&(e.contentType="application/x-www-form-urlencoded",e.data=e.data?{model:e.data}:{});if(g.emulateHTTP&&("PUT"===d||"DELETE"===d))g.emulateJSON&&(e.data._method=d),e.type="POST",e.beforeSend=function(a){a.setRequestHeader("X-HTTP-Method-Override",d)};"GET"!==e.type&&!g.emulateJSON&&(e.processData=!1);return i.ajax(f.extend(e,c))};g.wrapError=function(a,b,c){return function(d,e){e=d===b?e:d;a?a(b,e,c):b.trigger("error",b,e,c)}};var x=function(){},G=function(a,
|
||||
b,c){var d;d=b&&b.hasOwnProperty("constructor")?b.constructor:function(){a.apply(this,arguments)};f.extend(d,a);x.prototype=a.prototype;d.prototype=new x;b&&f.extend(d.prototype,b);c&&f.extend(d,c);d.prototype.constructor=d;d.__super__=a.prototype;return d},n=function(a,b){return!a||!a[b]?null:f.isFunction(a[b])?a[b]():a[b]},t=function(){throw Error('A "url" property or function must be specified');}}).call(this);
|
|
@ -0,0 +1,51 @@
|
|||
//Copyright (c) 2010 Nicholas C. Zakas. All rights reserved.
|
||||
//MIT License
|
||||
|
||||
function EventTarget(){
|
||||
this._listeners = {};
|
||||
}
|
||||
|
||||
EventTarget.prototype = {
|
||||
|
||||
constructor: EventTarget,
|
||||
|
||||
addListener: function(type, listener){
|
||||
if (typeof this._listeners[type] == "undefined"){
|
||||
this._listeners[type] = [];
|
||||
}
|
||||
|
||||
this._listeners[type].push(listener);
|
||||
},
|
||||
|
||||
fire: function(event){
|
||||
if (typeof event == "string"){
|
||||
event = { type: event };
|
||||
}
|
||||
if (!event.target){
|
||||
event.target = this;
|
||||
}
|
||||
|
||||
if (!event.type){ //falsy
|
||||
throw new Error("Event object missing 'type' property.");
|
||||
}
|
||||
|
||||
if (this._listeners[event.type] instanceof Array){
|
||||
var listeners = this._listeners[event.type];
|
||||
for (var i=0, len=listeners.length; i < len; i++){
|
||||
listeners[i].call(this, event);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
removeListener: function(type, listener){
|
||||
if (this._listeners[type] instanceof Array){
|
||||
var listeners = this._listeners[type];
|
||||
for (var i=0, len=listeners.length; i < len; i++){
|
||||
if (listeners[i] === listener){
|
||||
listeners.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: henne
|
||||
* Date: 23.03.12
|
||||
* Time: 00:51
|
||||
* Main Javascript file
|
||||
*/
|
||||
var events = new EventTarget();
|
||||
var roomDevices = [];
|
||||
var roomDeviceViews = [];
|
||||
Workspace = Backbone.Router.extend({
|
||||
routes:{
|
||||
"":"home",
|
||||
":id":"show_room"
|
||||
|
||||
},
|
||||
home: function() {
|
||||
function roomsLoadedHandler() {
|
||||
rooms.each(function(room) {
|
||||
var id = room.get('roomId');
|
||||
roomDevices[id] = new RoomDevices();
|
||||
roomDevices[id].url = '/resources/json/room' + id + '.json';
|
||||
roomDevices[id].fetch();
|
||||
});
|
||||
events.removeListener("roomsLoaded", roomsLoadedHandler);
|
||||
}
|
||||
events.addListener("roomsLoaded", roomsLoadedHandler);
|
||||
rooms.fetch();
|
||||
|
||||
},
|
||||
show_room: function(id) {
|
||||
this.home();
|
||||
function roomsLoadedHandlerTabSelect() {
|
||||
$('#room-tabs').tabs('select', id);
|
||||
events.removeListener("roomsLoaded", roomsLoadedHandlerTabSelect)
|
||||
}
|
||||
events.addListener("roomsLoaded", roomsLoadedHandlerTabSelect);
|
||||
|
||||
}
|
||||
});
|
||||
$(document).ready(function() {
|
||||
|
||||
window.rooms = new Rooms();
|
||||
window.roomsView = new RoomsView({collection: rooms});
|
||||
window.devices = new Devices();
|
||||
window.devicesView = new DevicesView({collection: devices});
|
||||
|
||||
window.App = new Workspace();
|
||||
Backbone.history.start()
|
||||
});
|
|
@ -1,3 +1,12 @@
|
|||
(function($) {
|
||||
window.Room = Backbone.Model.extend({});
|
||||
window.Rooms = Backbone.Collection.extend({
|
||||
model: Room,
|
||||
url: '/resources/json/rooms.json'
|
||||
});
|
||||
window.Device = Backbone.Model.extend({});
|
||||
|
||||
window.RoomDevices = Backbone.Collection.extend({
|
||||
model: Device
|
||||
});
|
||||
})(jQuery);
|
|
@ -0,0 +1,31 @@
|
|||
// Underscore.js 1.3.1
|
||||
// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
|
||||
// Underscore is freely distributable under the MIT license.
|
||||
// Portions of Underscore are inspired or borrowed from Prototype,
|
||||
// Oliver Steele's Functional, and John Resig's Micro-Templating.
|
||||
// For all details and documentation:
|
||||
// http://documentcloud.github.com/underscore
|
||||
(function(){function q(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return false;switch(e){case "[object String]":return a==String(c);case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source==
|
||||
c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return true;d.push(a);var f=0,g=true;if(e=="[object Array]"){if(f=a.length,g=f==c.length)for(;f--;)if(!(g=f in a==f in c&&q(a[f],c[f],d)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(b.has(a,h)&&(f++,!(g=b.has(c,h)&&q(a[h],c[h],d))))break;if(g){for(h in c)if(b.has(c,
|
||||
h)&&!f--)break;g=!f}}d.pop();return g}var r=this,G=r._,n={},k=Array.prototype,o=Object.prototype,i=k.slice,H=k.unshift,l=o.toString,I=o.hasOwnProperty,w=k.forEach,x=k.map,y=k.reduce,z=k.reduceRight,A=k.filter,B=k.every,C=k.some,p=k.indexOf,D=k.lastIndexOf,o=Array.isArray,J=Object.keys,s=Function.prototype.bind,b=function(a){return new m(a)};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports)exports=module.exports=b;exports._=b}else r._=b;b.VERSION="1.3.1";var j=b.each=
|
||||
b.forEach=function(a,c,d){if(a!=null)if(w&&a.forEach===w)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,f=a.length;e<f;e++){if(e in a&&c.call(d,a[e],e,a)===n)break}else for(e in a)if(b.has(a,e)&&c.call(d,a[e],e,a)===n)break};b.map=b.collect=function(a,c,b){var e=[];if(a==null)return e;if(x&&a.map===x)return a.map(c,b);j(a,function(a,g,h){e[e.length]=c.call(b,a,g,h)});if(a.length===+a.length)e.length=a.length;return e};b.reduce=b.foldl=b.inject=function(a,c,d,e){var f=arguments.length>2;a==
|
||||
null&&(a=[]);if(y&&a.reduce===y)return e&&(c=b.bind(c,e)),f?a.reduce(c,d):a.reduce(c);j(a,function(a,b,i){f?d=c.call(e,d,a,b,i):(d=a,f=true)});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(z&&a.reduceRight===z)return e&&(c=b.bind(c,e)),f?a.reduceRight(c,d):a.reduceRight(c);var g=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));return f?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect=
|
||||
function(a,c,b){var e;E(a,function(a,g,h){if(c.call(b,a,g,h))return e=a,true});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(A&&a.filter===A)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(B&&a.every===B)return a.every(c,b);j(a,function(a,g,h){if(!(e=
|
||||
e&&c.call(b,a,g,h)))return n});return e};var E=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(C&&a.some===C)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return n});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;return p&&a.indexOf===p?a.indexOf(c)!=-1:b=E(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c||a:a[c]).apply(a,d)})};b.pluck=
|
||||
function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a))return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b<e.computed&&(e={value:a,computed:b})});
|
||||
return e.value};b.shuffle=function(a){var b=[],d;j(a,function(a,f){f==0?b[0]=a:(d=Math.floor(Math.random()*(f+1)),b[f]=b[d],b[d]=a)});return b};b.sortBy=function(a,c,d){return b.pluck(b.map(a,function(a,b,g){return{value:a,criteria:c.call(d,a,b,g)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;return c<d?-1:c>d?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]};j(a,function(a,b){var c=e(a,b);(d[c]||(d[c]=[])).push(a)});return d};b.sortedIndex=function(a,
|
||||
c,d){d||(d=b.identity);for(var e=0,f=a.length;e<f;){var g=e+f>>1;d(a[g])<d(c)?e=g+1:f=g}return e};b.toArray=function(a){return!a?[]:a.toArray?a.toArray():b.isArray(a)?i.call(a):b.isArguments(a)?i.call(a):b.values(a)};b.size=function(a){return b.toArray(a).length};b.first=b.head=function(a,b,d){return b!=null&&!d?i.call(a,0,b):a[0]};b.initial=function(a,b,d){return i.call(a,0,a.length-(b==null||d?1:b))};b.last=function(a,b,d){return b!=null&&!d?i.call(a,Math.max(a.length-b,0)):a[a.length-1]};b.rest=
|
||||
b.tail=function(a,b,d){return i.call(a,b==null||d?1:b)};b.compact=function(a){return b.filter(a,function(a){return!!a})};b.flatten=function(a,c){return b.reduce(a,function(a,e){if(b.isArray(e))return a.concat(c?e:b.flatten(e));a[a.length]=e;return a},[])};b.without=function(a){return b.difference(a,i.call(arguments,1))};b.uniq=b.unique=function(a,c,d){var d=d?b.map(a,d):a,e=[];b.reduce(d,function(d,g,h){if(0==h||(c===true?b.last(d)!=g:!b.include(d,g)))d[d.length]=g,e[e.length]=a[h];return d},[]);
|
||||
return e};b.union=function(){return b.uniq(b.flatten(arguments,true))};b.intersection=b.intersect=function(a){var c=i.call(arguments,1);return b.filter(b.uniq(a),function(a){return b.every(c,function(c){return b.indexOf(c,a)>=0})})};b.difference=function(a){var c=b.flatten(i.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e<c;e++)d[e]=b.pluck(a,""+e);return d};b.indexOf=function(a,c,
|
||||
d){if(a==null)return-1;var e;if(d)return d=b.sortedIndex(a,c),a[d]===c?d:-1;if(p&&a.indexOf===p)return a.indexOf(c);for(d=0,e=a.length;d<e;d++)if(d in a&&a[d]===c)return d;return-1};b.lastIndexOf=function(a,b){if(a==null)return-1;if(D&&a.lastIndexOf===D)return a.lastIndexOf(b);for(var d=a.length;d--;)if(d in a&&a[d]===b)return d;return-1};b.range=function(a,b,d){arguments.length<=1&&(b=a||0,a=0);for(var d=arguments[2]||1,e=Math.max(Math.ceil((b-a)/d),0),f=0,g=Array(e);f<e;)g[f++]=a,a+=d;return g};
|
||||
var F=function(){};b.bind=function(a,c){var d,e;if(a.bind===s&&s)return s.apply(a,i.call(arguments,1));if(!b.isFunction(a))throw new TypeError;e=i.call(arguments,2);return d=function(){if(!(this instanceof d))return a.apply(c,e.concat(i.call(arguments)));F.prototype=a.prototype;var b=new F,g=a.apply(b,e.concat(i.call(arguments)));return Object(g)===g?g:b}};b.bindAll=function(a){var c=i.call(arguments,1);c.length==0&&(c=b.functions(a));j(c,function(c){a[c]=b.bind(a[c],a)});return a};b.memoize=function(a,
|
||||
c){var d={};c||(c=b.identity);return function(){var e=c.apply(this,arguments);return b.has(d,e)?d[e]:d[e]=a.apply(this,arguments)}};b.delay=function(a,b){var d=i.call(arguments,2);return setTimeout(function(){return a.apply(a,d)},b)};b.defer=function(a){return b.delay.apply(b,[a,1].concat(i.call(arguments,1)))};b.throttle=function(a,c){var d,e,f,g,h,i=b.debounce(function(){h=g=false},c);return function(){d=this;e=arguments;var b;f||(f=setTimeout(function(){f=null;h&&a.apply(d,e);i()},c));g?h=true:
|
||||
a.apply(d,e);i();g=true}};b.debounce=function(a,b){var d;return function(){var e=this,f=arguments;clearTimeout(d);d=setTimeout(function(){d=null;a.apply(e,f)},b)}};b.once=function(a){var b=false,d;return function(){if(b)return d;b=true;return d=a.apply(this,arguments)}};b.wrap=function(a,b){return function(){var d=[a].concat(i.call(arguments,0));return b.apply(this,d)}};b.compose=function(){var a=arguments;return function(){for(var b=arguments,d=a.length-1;d>=0;d--)b=[a[d].apply(this,b)];return b[0]}};
|
||||
b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=J||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.defaults=function(a){j(i.call(arguments,
|
||||
1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return q(a,b,[])};b.isEmpty=function(a){if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=o||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};
|
||||
b.isArguments=function(a){return l.call(a)=="[object Arguments]"};if(!b.isArguments(arguments))b.isArguments=function(a){return!(!a||!b.has(a,"callee"))};b.isFunction=function(a){return l.call(a)=="[object Function]"};b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)=="[object Date]"};
|
||||
b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return I.call(a,b)};b.noConflict=function(){r._=G;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e<a;e++)b.call(d,e)};b.escape=function(a){return(""+a).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")};b.mixin=function(a){j(b.functions(a),
|
||||
function(c){K(c,b[c]=a[c])})};var L=0;b.uniqueId=function(a){var b=L++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var t=/.^/,u=function(a){return a.replace(/\\\\/g,"\\").replace(/\\'/g,"'")};b.template=function(a,c){var d=b.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.escape||t,function(a,b){return"',_.escape("+
|
||||
u(b)+"),'"}).replace(d.interpolate||t,function(a,b){return"',"+u(b)+",'"}).replace(d.evaluate||t,function(a,b){return"');"+u(b).replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return c?e(c,b):function(a){return e.call(this,a,b)}};b.chain=function(a){return b(a).chain()};var m=function(a){this._wrapped=a};b.prototype=m.prototype;var v=function(a,c){return c?b(a).chain():a},K=function(a,c){m.prototype[a]=
|
||||
function(){var a=i.call(arguments);H.call(a,this._wrapped);return v(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];m.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);var e=d.length;(a=="shift"||a=="splice")&&e===0&&delete d[0];return v(d,this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];m.prototype[a]=function(){return v(b.apply(this._wrapped,arguments),this._chain)}});m.prototype.chain=function(){this._chain=
|
||||
true;return this};m.prototype.value=function(){return this._wrapped}}).call(this);
|
|
@ -0,0 +1,56 @@
|
|||
window.RoomsView = Backbone.View.extend({
|
||||
initialize: function() {
|
||||
this.collection.bind('reset', this.render, this);
|
||||
},
|
||||
render: function() {
|
||||
$('#room-tabs').tabs('destroy');
|
||||
this.template = Handlebars.compile($("#room-tabs-template").html());
|
||||
var rooms = {'rooms': this.collection.toJSON()};
|
||||
$('#room-tabs').html(this.template(rooms)).tabs({
|
||||
select: function(event, ui) {
|
||||
//set hashtag?
|
||||
}
|
||||
});
|
||||
events.fire("roomsLoaded");
|
||||
|
||||
return this;
|
||||
}
|
||||
});
|
||||
window.LampelView = Backbone.View.extend({
|
||||
initialize: function() {
|
||||
this.collection.bind('reset', this.render, this);
|
||||
},
|
||||
render: function() {
|
||||
events.fire("lampelLoaded");
|
||||
|
||||
return this;
|
||||
}
|
||||
});
|
||||
window.BuzzerView = Backbone.View.extend({
|
||||
initialize: function() {
|
||||
this.collection.bind('reset', this.render, this);
|
||||
},
|
||||
render: function() {
|
||||
events.fire("buzzerLoaded");
|
||||
|
||||
return this;
|
||||
}
|
||||
});
|
||||
window.Par56View = Backbone.View.extend({
|
||||
initialize: function() {
|
||||
this.collection.bind('reset', this.render, this);
|
||||
},
|
||||
render: function() {
|
||||
events.fire("par56Loaded");
|
||||
|
||||
return this;
|
||||
}
|
||||
});
|
||||
window.DevicesView = Backbone.View.extend({
|
||||
initialize: function() {
|
||||
this.collection.bind('reset', this.render, this);
|
||||
},
|
||||
render: function() {
|
||||
|
||||
}
|
||||
});
|
|
@ -0,0 +1,11 @@
|
|||
[
|
||||
{
|
||||
"type":"Buzzer",
|
||||
"deviceId":0,
|
||||
"deviceName":"Buzzer",
|
||||
"picture":null,
|
||||
"options": {
|
||||
"state":0
|
||||
}
|
||||
}
|
||||
]
|
|
@ -0,0 +1,85 @@
|
|||
[
|
||||
{
|
||||
"startAddress":1,
|
||||
"type":"Par56Spot",
|
||||
"deviceId":0,
|
||||
"deviceName":"Par56 Lampe 1",
|
||||
"picture":null,
|
||||
"options": {
|
||||
"red":0,
|
||||
"green":0,
|
||||
"blue":0
|
||||
}
|
||||
},
|
||||
{
|
||||
"startAddress":6,
|
||||
"type":"Par56Spot",
|
||||
"deviceId":1,
|
||||
"deviceName":"Par56 Lampe 2",
|
||||
"picture":null,
|
||||
"options": {
|
||||
"red":0,
|
||||
"green":0,
|
||||
"blue":0
|
||||
}
|
||||
},
|
||||
{
|
||||
"startAddress":11,
|
||||
"type":"Par56Spot",
|
||||
"deviceId":2,
|
||||
"deviceName":"Par56 Lampe 3",
|
||||
"picture":null,
|
||||
"options": {
|
||||
"red":0,
|
||||
"green":0,
|
||||
"blue":0
|
||||
}
|
||||
},
|
||||
{
|
||||
"startAddress":16,
|
||||
"type":"Par56Spot",
|
||||
"deviceId":3,
|
||||
"deviceName":"Par56 Lampe 5",
|
||||
"picture":null,
|
||||
"options": {
|
||||
"red":0,
|
||||
"green":0,
|
||||
"blue":0
|
||||
}
|
||||
},
|
||||
{
|
||||
"startAddress":21,
|
||||
"type":"Strobe1500",
|
||||
"deviceId":4,
|
||||
"deviceName":"Stroboskop 1",
|
||||
"picture":null,
|
||||
"options": {
|
||||
"mode":0,
|
||||
"speed":0,
|
||||
"intensity":0
|
||||
}
|
||||
},
|
||||
{
|
||||
"startAddress":508,
|
||||
"type":"Par56Spot",
|
||||
"deviceId":5,
|
||||
"deviceName":"Par56 Lampe 5",
|
||||
"picture":null,
|
||||
"options": {
|
||||
"red":0,
|
||||
"green":0,
|
||||
"blue":0
|
||||
}
|
||||
},
|
||||
{
|
||||
"type":"Lampel",
|
||||
"deviceId":6,
|
||||
"deviceName":"Lampel",
|
||||
"picture":null,
|
||||
"options": {
|
||||
"red":0,
|
||||
"green":0,
|
||||
"blue":0
|
||||
}
|
||||
},
|
||||
]
|
|
@ -0,0 +1,7 @@
|
|||
[
|
||||
{"roomId": 0, "roomName": "Global"},
|
||||
{"roomId": 1, "roomName": "Raum 1"},
|
||||
{"roomId": 2, "roomName": "Raum 2"},
|
||||
{"roomId": 3, "roomName": "Raum 3"},
|
||||
{"roomId": 4, "roomName": "Raum 4"}
|
||||
]
|
|
@ -0,0 +1,40 @@
|
|||
package de.ctdo.bunti.control;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
//@ContextConfiguration(locations = { "classpath:/META-INF/spring/root-context.xml","classpath:/de/ctdo/bunti/hibernate-test-context.xml" })
|
||||
//@RunWith(SpringJUnit4ClassRunner.class)
|
||||
//public class BuntiControllerImplTest {
|
||||
|
||||
// @Autowired
|
||||
// BuntiController dut;
|
||||
//
|
||||
// @Test
|
||||
// public void testUpdateDeviceData() throws Exception {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetAllRooms() throws Exception {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetRoomById() throws Exception {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetAllDevices() throws Exception {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetDeviceById() throws Exception {
|
||||
//
|
||||
// }
|
||||
//}
|
|
@ -1,23 +0,0 @@
|
|||
package de.ctdo.bunti.control;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
public class BuntiControllerTest {
|
||||
|
||||
BuntiControllerImpl dut;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
dut = new BuntiControllerImpl();
|
||||
// dut.setDevicesDAO(daoMock);
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void testSetDevice() throws Exception {
|
||||
// Map<String,Object> options = new HashMap<String, Object>();
|
||||
// options.put("optionA", "valueA");
|
||||
// options.put("optionB", 42);
|
||||
// assertTrue(dut.updateDeviceData(12, options));
|
||||
// }
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package de.ctdo.bunti.dao;
|
||||
|
||||
import de.ctdo.bunti.model.BuntiDMXDevice;
|
||||
import de.ctdo.bunti.model.BuntiDevice;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
|
||||
@ContextConfiguration(locations = { "classpath:/de/ctdo/bunti/hibernate-test-context.xml" })
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class BuntiDevicesDAOImplTest {
|
||||
|
||||
@Autowired
|
||||
BuntiDevicesDAO dut;
|
||||
|
||||
@Test
|
||||
public void testGetAllDMXDevices() throws Exception {
|
||||
List<BuntiDMXDevice> deviceList = dut.getAllDMXDevices();
|
||||
assertEquals(4, deviceList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllDevices() throws Exception {
|
||||
List<BuntiDevice> deviceList = dut.getAllDevices();
|
||||
assertEquals(4, deviceList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDeviceById() throws Exception {
|
||||
BuntiDevice device = dut.getDeviceById(2);
|
||||
|
||||
assertEquals("Lampe2", device.getDeviceName());
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package de.ctdo.bunti.dao;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
|
||||
@ContextConfiguration(locations = { "classpath:/de/ctdo/bunti/hibernate-test-context.xml" })
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class RoomsDAOImplTest {
|
||||
|
||||
@Autowired
|
||||
RoomsDAO dut;
|
||||
|
||||
@Test
|
||||
// @Transactional
|
||||
public void testGetRooms() throws Exception {
|
||||
assertEquals(4, dut.getRooms().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRoomKueche() throws Exception {
|
||||
assertEquals("Kueche", dut.getRoom(1).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRoomKuecheError() throws Exception {
|
||||
assertNull(dut.getRoom(23));
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package de.ctdo.bunti.dmx;
|
||||
|
||||
import de.ctdo.bunti.dmx.model.DMXChannel;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package de.ctdo.bunti.dmx;
|
||||
|
||||
import de.ctdo.bunti.dmx.model.DMXChannel;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -36,7 +36,10 @@ public class DMXMixerImplTest {
|
|||
|
||||
@Test
|
||||
public void testUpdateDevice() throws Exception {
|
||||
BuntiDevice device = new Par56Spot(23,42,"deviceName");
|
||||
Par56Spot device = new Par56Spot();
|
||||
device.setId(23);
|
||||
device.setStartAddress(42);
|
||||
device.setDeviceName("deviceName");
|
||||
Map<String,Object> options = new HashMap<String, Object>();
|
||||
options.put("red", 44);
|
||||
assertTrue(dut.updateDevice(device, options));
|
||||
|
@ -44,7 +47,10 @@ public class DMXMixerImplTest {
|
|||
|
||||
@Test
|
||||
public void testUpdateDeviceWrong1() throws Exception {
|
||||
BuntiDevice device = new Par56Spot(23,42,"deviceName");
|
||||
Par56Spot device = new Par56Spot();
|
||||
device.setId(23);
|
||||
device.setStartAddress(42);
|
||||
device.setDeviceName("deviceName");
|
||||
assertFalse(dut.updateDevice(device, null));
|
||||
}
|
||||
|
||||
|
@ -57,14 +63,20 @@ public class DMXMixerImplTest {
|
|||
|
||||
@Test
|
||||
public void testUpdateDeviceWrong3() throws Exception {
|
||||
BuntiDevice device = new Par56Spot(23,42,"deviceName");
|
||||
Par56Spot device = new Par56Spot();
|
||||
device.setId(23);
|
||||
device.setStartAddress(42);
|
||||
device.setDeviceName("deviceName");
|
||||
Map<String,Object> options = new HashMap<String, Object>();
|
||||
assertFalse(dut.updateDevice(device, options));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateDeviceWrong4() throws Exception {
|
||||
BuntiDevice device = new Par56Spot(23,42,"deviceName");
|
||||
Par56Spot device = new Par56Spot();
|
||||
device.setId(23);
|
||||
device.setStartAddress(42);
|
||||
device.setDeviceName("deviceName");
|
||||
Map<String,Object> options = new HashMap<String, Object>();
|
||||
options.put("rednonexistent", 44);
|
||||
assertFalse(dut.updateDevice(device, options));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package de.ctdo.bunti.model;
|
||||
|
||||
import de.ctdo.bunti.dmx.DMXChannel;
|
||||
import de.ctdo.bunti.dmx.model.DMXChannel;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -16,7 +16,10 @@ public class BuntiDMXDeviceTest {
|
|||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
dut = new Par56Spot(DEVICEID,STARTADDRESS,"device");
|
||||
dut = new Par56Spot();
|
||||
dut.setId(23);
|
||||
dut.setStartAddress(42);
|
||||
dut.setDeviceName("deviceName");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -139,7 +142,7 @@ public class BuntiDMXDeviceTest {
|
|||
|
||||
@Test
|
||||
public void testGetDeviceId() throws Exception {
|
||||
assertEquals(DEVICEID, dut.getDeviceId());
|
||||
assertEquals(DEVICEID, dut.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -9,8 +9,10 @@ public class Par56SpotTest {
|
|||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
dut = new Par56Spot(23,42,"device");
|
||||
|
||||
dut = new Par56Spot();
|
||||
dut.setId(23);
|
||||
dut.setStartAddress(42);
|
||||
dut.setDeviceName("device");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -10,8 +10,10 @@ public class Strobe1500Test {
|
|||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
dut = new Strobe1500(23,42,"device");
|
||||
|
||||
dut = new Strobe1500();
|
||||
dut.setId(23);
|
||||
dut.setStartAddress(42);
|
||||
dut.setDeviceName("device");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="H2">
|
||||
<jdbc:script location="classpath:init_schema.sql" />
|
||||
<jdbc:script location="classpath:init_data.sql" />
|
||||
</jdbc:embedded-database>
|
||||
|
||||
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
|
||||
<property name="packagesToScan" value="de.ctdo.bunti.model"/>
|
||||
<property name="hibernateProperties">
|
||||
<props>
|
||||
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
|
||||
<prop key="hibernate.show_sql">true</prop>
|
||||
<!--<prop key="hibernate.hbm2ddl.auto">create</prop>-->
|
||||
</props>
|
||||
</property>
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="roomsDAO" class="de.ctdo.bunti.dao.RoomsDAOImpl">
|
||||
<property name="sessionFactory" ref="hibernateSessionFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="devicesDAO" class="de.ctdo.bunti.dao.BuntiDevicesDAOImpl">
|
||||
<property name="sessionFactory" ref="hibernateSessionFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
|
||||
<property name="sessionFactory" ref="hibernateSessionFactory" />
|
||||
</bean>
|
||||
|
||||
<tx:annotation-driven />
|
||||
|
||||
</beans>
|
Loading…
Reference in New Issue