-
{/* Schematic editor header, toolbar and left side pane */}
-
} resToolbar={
} sidebar={
} />
+
}
+ resToolbar={
+
+ }
+ sidebar={
}
+ />
{/* Grid for drawing and designing circuits */}
@@ -77,9 +87,9 @@ export default function SchematiEditor (props) {
{/* Schematic editor Right side pane */}
-
+
- )
+ );
}
diff --git a/eda-frontend/src/redux/actions/dashboardActions.js b/eda-frontend/src/redux/actions/dashboardActions.js
index dc356d44d..b11adec9c 100644
--- a/eda-frontend/src/redux/actions/dashboardActions.js
+++ b/eda-frontend/src/redux/actions/dashboardActions.js
@@ -105,7 +105,7 @@ export const fetchPublicProjects = () => (dispatch, getState) => {
}
// Api call for deleting saved schematic
-export const deleteSchematic = (saveId) => (dispatch, getState) => {
+export const deleteSchematic = (saveId,version,branch) => (dispatch, getState) => {
const token = getState().authReducer.token
const config = {
headers: {
@@ -117,7 +117,7 @@ export const deleteSchematic = (saveId) => (dispatch, getState) => {
config.headers.Authorization = `Token ${token}`
}
- api.delete('save/' + saveId, config)
+ api.delete('save/' + saveId + "/" + version+ "/" + branch, config)
.then(
(res) => {
if (res.status === 200) {
diff --git a/eda-frontend/src/redux/actions/saveSchematicActions.js b/eda-frontend/src/redux/actions/saveSchematicActions.js
index 751009b36..f6b76740f 100644
--- a/eda-frontend/src/redux/actions/saveSchematicActions.js
+++ b/eda-frontend/src/redux/actions/saveSchematicActions.js
@@ -5,110 +5,157 @@ import GallerySchSample from '../../utils/GallerySchSample'
import { renderGalleryXML } from '../../components/SchematicEditor/Helper/ToolbarTools'
import { setTitle } from './index'
import { fetchLibrary, removeLibrary } from './schematicEditorActions'
+import randomstring from "randomstring"
import { fetchProject } from './projectActions'
export const setSchTitle = (title) => (dispatch) => {
dispatch({
type: actions.SET_SCH_TITLE,
payload: {
- title: title
- }
- })
-}
+ title: title,
+ },
+ });
+};
export const setSchDescription = (description) => (dispatch) => {
dispatch({
type: actions.SET_SCH_DESCRIPTION,
payload: {
- description: description
- }
- })
-}
+ description: description,
+ },
+ });
+};
export const setSchXmlData = (xmlData) => (dispatch) => {
dispatch({
type: actions.SET_SCH_XML_DATA,
payload: {
- xmlData: xmlData
- }
- })
-}
+ xmlData: xmlData,
+ },
+ });
+};
// Api call to save new schematic or updating saved schematic.
-export const saveSchematic = (title, description, xml, base64) => (dispatch, getState) => {
+export const saveSchematic = (title, description, xml, base64,newBranch = false, branchName = null, setVersions, versions) => (dispatch, getState) => {
var libraries = []
getState().schematicEditorReducer.libraries.forEach(e => { libraries.push(e.id) })
console.log(libraries)
- const body = {
+ var body = {
data_dump: xml,
base64_image: base64,
name: title,
description: description,
esim_libraries: JSON.stringify([...libraries])
}
-
// Get token from localstorage
- const token = getState().authReducer.token
- const schSave = getState().saveSchematicReducer
+ const token = getState().authReducer.token;
+ const schSave = getState().saveSchematicReducer;
+ console.log(schSave)
// add headers
const config = {
headers: {
- 'Content-Type': 'application/x-www-form-urlencoded'
- }
- }
+ "Content-Type": "application/x-www-form-urlencoded",
+ },
+ };
// If token available add to headers
if (token) {
- config.headers.Authorization = `Token ${token}`
+ config.headers.Authorization = `Token ${token}`;
}
-
- if (schSave.isSaved) {
- // Updating saved schemaic
- api.post('save/' + schSave.details.save_id, queryString.stringify(body), config)
- .then(
- (res) => {
- dispatch({
- type: actions.SET_SCH_SAVED,
- payload: res.data
- })
- }
- )
- .catch((err) => { console.error(err) })
- } else {
- // saving new schematic
- api.post('save', queryString.stringify(body), config)
- .then(
- (res) => {
+ if(!newBranch) {
+ console.log("New Version not Branch")
+ body.version = randomstring.generate({
+ length: 20,
+ });
+ if (schSave.isSaved) {
+ // Updating saved schemaic
+ body.save_id = schSave.details.save_id;
+ body.branch=schSave.details.branch
+ api
+ .post("save", queryString.stringify(body), config)
+ .then((res) => {
+ if(!res.data.duplicate)
+ setVersions(res.data.version,false,null)
+ dispatch({
+ type: actions.SET_SCH_SAVED,
+ payload: res.data,
+ });
+ })
+ .catch((err) => {
+ console.error(err);
+ });
+ } else {
+ body.branch = "master"
+ // saving new schematic
+ api
+ .post("save", queryString.stringify(body), config)
+ .then((res) => {
+ setVersions(res.data.version,true,res.data.save_id)
+ dispatch({
+ type: actions.SET_SCH_SAVED,
+ payload: res.data,
+ });
+ })
+ .catch((err) => {
+ console.error(err);
+ });
+ }
+ }
+ else {
+ console.log("New Branch not Version")
+ var flag = 0
+ for (var i = 0; i < versions.length; i++){
+ if (branchName === versions[i][0])
+ flag=1
+ }
+ if (!flag) {
+ body.save_id = schSave.details.save_id;
+ body.branch = branchName
+ body.version = schSave.details.version
+ api
+ .post("save", queryString.stringify(body), config)
+ .then((res) => {
+ var temp = versions
+ var d = new Date(res.data.save_time)
+ res.data.date = d.getDate() + "/" + d.getMonth() + "/" + d.getFullYear()
+ res.data.time = d.getHours() + ":" + d.getMinutes()
+ if (d.getMinutes() < 10) {
+ res.data.time = d.getHours() + ":0" + d.getMinutes()
+ }
+ temp.push([res.data.branch, [res.data]])
+ setVersions(temp)
dispatch({
type: actions.SET_SCH_SAVED,
- payload: res.data
- })
- }
- )
- .catch((err) => { console.error(err) })
+ payload: res.data,
+ });
+ })
+ .catch((err) => {
+ console.error(err);
+ })
+ }
}
-}
+};
// Action for Loading on-cloud saved schematics
-export const fetchSchematic = (saveId) => (dispatch, getState) => {
+export const fetchSchematic = (saveId, version,branch) => (dispatch, getState) => {
// Get token from localstorage
- const token = getState().authReducer.token
+ const token = getState().authReducer.token;
// add headers
const config = {
headers: {
- 'Content-Type': 'application/x-www-form-urlencoded'
- }
- }
+ "Content-Type": "application/x-www-form-urlencoded",
+ },
+ };
// If token available add to headers
if (token) {
- config.headers.Authorization = `Token ${token}`
+ config.headers.Authorization = `Token ${token}`;
}
// console.log('Already Saved')
- api.get('save/' + saveId, config)
+ api.get('save/' + saveId + "/" + version + "/" + branch, config)
.then(
(res) => {
dispatch({
@@ -134,56 +181,59 @@ export const fetchSchematic = (saveId) => (dispatch, getState) => {
export const setSchShared = (share) => (dispatch, getState) => {
// Get token from localstorage
- const token = getState().authReducer.token
- const schSave = getState().saveSchematicReducer
+ const token = getState().authReducer.token;
+ const schSave = getState().saveSchematicReducer;
// add headers
const config = {
headers: {
- 'Content-Type': 'application/json'
- }
- }
+ "Content-Type": "application/json",
+ },
+ };
// If token available add to headers
if (token) {
- config.headers.Authorization = `Token ${token}`
+ config.headers.Authorization = `Token ${token}`;
}
- var isShared
+ var isShared;
if (share === true) {
- isShared = 'on'
+ isShared = "on";
} else {
- isShared = 'off'
+ isShared = "off";
}
- api.post('save/' + schSave.details.save_id + '/sharing/' + isShared, {}, config)
- .then(
- (res) => {
- dispatch({
- type: actions.SET_SCH_SHARED,
- payload: res.data
- })
- }
+ api
+ .post(
+ "save/" + schSave.details.save_id + "/sharing/" + isShared+"/"+schSave.details.version+"/"+schSave.details.branch,
+ {},
+ config
)
- .catch((err) => { console.error(err) })
-}
-//Action for Creating a circuit
-
+ .then((res) => {
+ dispatch({
+ type: actions.SET_SCH_SHARED,
+ payload: res.data,
+ });
+ })
+ .catch((err) => {
+ console.error(err);
+ });
+};
// Action for Loading Gallery schematics
export const loadGallery = (Id) => (dispatch, getState) => {
- var data = GallerySchSample[Id]
+ var data = GallerySchSample[Id];
dispatch({
type: actions.LOAD_GALLERY,
- payload: data
- })
- dispatch(setTitle('* ' + data.name))
- dispatch(setSchTitle(data.name))
- dispatch(setSchDescription(data.description))
- dispatch(setSchXmlData(data.data_dump))
- renderGalleryXML(data.data_dump)
-}
+ payload: data,
+ });
+ dispatch(setTitle("* " + data.name));
+ dispatch(setSchTitle(data.name));
+ dispatch(setSchDescription(data.description));
+ dispatch(setSchXmlData(data.data_dump));
+ renderGalleryXML(data.data_dump);
+};
// Action for Loading local exported schematics
export const openLocalSch = (obj) => (dispatch, getState) => {
@@ -218,4 +268,4 @@ export const makeCopy = (saveID) => (dispatch, getState) => {
win.focus();
})
.catch(error => console.log(error))
-}
\ No newline at end of file
+}
diff --git a/esim-cloud-backend/saveAPI/admin.py b/esim-cloud-backend/saveAPI/admin.py
index 02ad2f293..e0dcf3adb 100644
--- a/esim-cloud-backend/saveAPI/admin.py
+++ b/esim-cloud-backend/saveAPI/admin.py
@@ -5,4 +5,5 @@
@admin.register(StateSave)
class UserCircuits(admin.ModelAdmin):
list_display = ('name', 'is_arduino', 'base64_image',
- 'save_time', 'create_time')
+ 'save_time', 'create_time', "version")
+ list_filter = ('version', 'save_id',)
diff --git a/esim-cloud-backend/saveAPI/models.py b/esim-cloud-backend/saveAPI/models.py
index 80a78e7ad..9379ef54f 100644
--- a/esim-cloud-backend/saveAPI/models.py
+++ b/esim-cloud-backend/saveAPI/models.py
@@ -11,23 +11,26 @@
class StateSave(models.Model):
+ id = models.AutoField(primary_key=True)
name = models.CharField(max_length=200, null=True)
description = models.CharField(max_length=400, null=True)
save_time = models.DateTimeField(auto_now=True, db_index=True)
create_time = models.DateTimeField(auto_now_add=True)
- save_id = models.UUIDField(
- primary_key=True, default=uuid.uuid4)
+ save_id = models.UUIDField(default=uuid.uuid4)
data_dump = models.TextField(null=False)
shared = models.BooleanField(default=False)
owner = models.ForeignKey(
get_user_model(), null=True, on_delete=models.CASCADE)
base64_image = models.ImageField(
upload_to='circuit_images', storage=file_storage, null=True)
+ version = models.CharField(max_length=20, null=False)
+ branch = models.CharField(max_length=20,null=False)
is_arduino = models.BooleanField(default=False, null=False)
esim_libraries = models.ManyToManyField(Library)
project = models.OneToOneField(to=Project,on_delete=models.CASCADE,null=True)
def save(self, *args, **kwargs):
super(StateSave, self).save(*args, **kwargs)
+
def __str__(self):
- return self.name
\ No newline at end of file
+ return self.name
diff --git a/esim-cloud-backend/saveAPI/serializers.py b/esim-cloud-backend/saveAPI/serializers.py
index 89bb0c24e..4777ce47f 100644
--- a/esim-cloud-backend/saveAPI/serializers.py
+++ b/esim-cloud-backend/saveAPI/serializers.py
@@ -41,8 +41,8 @@ class Meta:
model = StateSave
fields = ('save_time', 'save_id', 'data_dump', 'name', 'description',
- 'owner', 'shared', 'base64_image', 'create_time',
- 'is_arduino', 'esim_libraries','project_id')
+ 'owner', 'shared', 'base64_image', 'create_time','version',
+ 'branch', 'is_arduino', 'esim_libraries','project_id')
class SaveListSerializer(serializers.ModelSerializer):
base64_image = Base64ImageField(max_length=None, use_url=True)
@@ -51,4 +51,5 @@ class SaveListSerializer(serializers.ModelSerializer):
class Meta:
model = StateSave
fields = ('save_time', 'save_id', 'name', 'description',
- 'shared', 'base64_image', 'create_time', 'esim_libraries','project_id')
+ 'shared', 'base64_image', 'create_time', 'version',
+ 'branch', 'esim_libraries','project_id')
diff --git a/esim-cloud-backend/saveAPI/urls.py b/esim-cloud-backend/saveAPI/urls.py
index 5bbc71016..b5b3c69a8 100644
--- a/esim-cloud-backend/saveAPI/urls.py
+++ b/esim-cloud-backend/saveAPI/urls.py
@@ -22,15 +22,21 @@
path('save/arduino/list', saveAPI_views.ArduinoSaveList.as_view(),
name='ArduinoSaveList'),
- path('save/