Skip to content

Commit

Permalink
Added IPFS support for image upload / download
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Flanagin committed Jul 30, 2018
1 parent 8860380 commit 6ddcf57
Show file tree
Hide file tree
Showing 13 changed files with 230 additions and 32 deletions.
14 changes: 11 additions & 3 deletions Desktop/Educator/GeneralInfoDashBoard.qml
@@ -1,6 +1,7 @@
import QtQuick 2.11
import QtQuick.Controls 2.4
import "../theme"
import "../General"
import "../Educator/course.js" as Courses
import "../Educator/students.js" as Students
import "../Educator/scheduler.js" as Schedule
Expand Down Expand Up @@ -104,24 +105,31 @@ Item {
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("No Classes Today")
font.bold: true
visible: if (daysClasses.count === 0) {
visible: if (dlist.height >= 0) {
true
} else {
false
}
}

Grid {
id:dlist
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width * 0.98
spacing: 10
columns: 5

Repeater {
model: daysClasses
model: DayList {

day: d.getDate()
month: d.getMonth()
weekday: d.getDay()
educator: "login"
}

ESborder {
width: thisWindow.width / 5
width: thisWindow.width / 5.5
height: classColumn.height + thisWindow.height * 0.1

state: "Active"
Expand Down
10 changes: 5 additions & 5 deletions Desktop/Educator/LessonPlanWizard.qml
Expand Up @@ -115,11 +115,11 @@ ESborder {
spacing: width * 0.03

Text {
text: qsTr("Course: " + courseName)
text: qsTr("Course: " + Scrubber.recoverSpecial(courseName))
}

Text {
text: qsTr("Unit: " + unitTitle)
text: qsTr("Unit: " + Scrubber.recoverSpecial(unitTitle))
}

Rectangle {
Expand Down Expand Up @@ -722,11 +722,11 @@ ESborder {
}

Text {
text: qsTr("Course: " + courseName)
text: qsTr("Course: " + Scrubber.recoverSpecial(courseName))
}

Text {
text: qsTr("Unit: " + unitTitle)
text: qsTr("Unit: " + Scrubber.recoverSpecial(unitTitle))
}

Text {
Expand Down Expand Up @@ -791,7 +791,7 @@ ESborder {
aboutBox.text), Scrubber.replaceSpecials(objectiveBox.text), Scrubber.replaceSpecials(
resourceBox.text), Scrubber.replaceSpecials(otherResourcesBox.text), Scrubber.replaceSpecials(
guidedQuestions.toString()), Scrubber.replaceSpecials(lessonSequence.text),
Scrubber.replaceSpecials(studentProduct.text), Scrubber.replaceSpecials(reviewQuestions.toString()), 0)
Scrubber.replaceSpecials(reviewQuestions.toString()), 0)
thisWindow.state = "inActive"
}
}
Expand Down
4 changes: 2 additions & 2 deletions Desktop/Educator/course.js
Expand Up @@ -36,14 +36,14 @@ function saveUnit(userid, coursenumber, name, objective, about, creationdate) {
})
}

function saveLesson(userid, coursenumber, unitnumber, name, lessonNum, duration, about, objective, supplies, resources, guidingQuestions, lessonSequence, studentProduct, reviewQuestions, creationdate) {
function saveLesson(userid, coursenumber, unitnumber, name, lessonNum, duration, about, objective, supplies, resources, guidingQuestions, lessonSequence, reviewQuestions, creationdate) {

var d = new Date()

db.transaction(function (tx) {
var data = [userid, userCode, 0, coursenumber, unitnumber, name.replace(
/ /g,
"_"), lessonNum, duration, about, objective, supplies, resources, guidingQuestions, lessonSequence, studentProduct, reviewQuestions, d.getTime(
"_"), lessonNum, duration, about, objective, supplies, resources, guidingQuestions, lessonSequence, " ", reviewQuestions, d.getTime(
), d.getTime()]
var dtable = "INSERT INTO Lessons VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"

Expand Down
24 changes: 22 additions & 2 deletions Desktop/General/FieldEdit.qml
@@ -1,5 +1,6 @@
import QtQuick 2.11
import QtQuick.Controls 2.2
import Process 1.0

import "../theme"
import "../plugins"
Expand All @@ -8,6 +9,7 @@ import "../Educator"
import "../Educator/course.js" as Scripts
import "../plugins/text.js" as Scrubber
import "../plugins/markdown.js" as MD
import "./ipfs.js" as IPFS

ESborder {
id: thisWindow
Expand All @@ -19,6 +21,7 @@ ESborder {
property string where: ""
property real itemId: 0
property string existing: ""
property string newfile: ""

onStateChanged: if (state == "Active") {
existing = Scripts.pullField(field, where, itemId)
Expand Down Expand Up @@ -119,6 +122,8 @@ ESborder {
}

TextArea {
id: changeBox

visible: switch (thisWindow.field) {
case "rq":
false
Expand All @@ -127,13 +132,13 @@ ESborder {
true
break
}
id: changeBox
anchors.fill: parent
horizontalAlignment: Text.AlignLeft
wrapMode: Text.WordWrap
selectByMouse: true
text: Scrubber.recoverSpecial(existing)
padding: 5

}

ListView {
Expand Down Expand Up @@ -221,7 +226,10 @@ ESborder {

Button {
text: qsTr("Add Image")
onClicked: fileadd.visible = true
onClicked: {
fileadd.type = "general"
fileadd.visible = true
}
background: ESTextField {
}
}
Expand Down Expand Up @@ -319,4 +327,16 @@ ESborder {
id: fileadd
visible: false
}


Process {
id: ipfs
property string type: "general"
property string newfile: ""
onReadyRead: {
newfile = readAll()
changeBox.text = changeBox.text+"\n ![IMG]("+IPFS.mediaAdd(newfile,type)+")"
}
}

}
32 changes: 22 additions & 10 deletions Desktop/General/Profile.qml
Expand Up @@ -7,9 +7,11 @@ import Qt.labs.calendar 1.0

import "../theme"
import "../Educator"
import "./general.js" as Scripts
import "../plugins"

import "./general.js" as Scripts
import "./ipfs.js" as IPFS

Item {
id: thisWindow

Expand All @@ -21,6 +23,7 @@ Item {
property string userState: ""
property string userid: ""
property string userAbout: ""
property string tempImg:""

states: [

Expand Down Expand Up @@ -70,6 +73,10 @@ Item {
anchors.fill: parent
}

onStateChanged: {
profileImage.source = IPFS.grabImage(userCode,"profile")
}

Text {
id: title
anchors.top: parent.top
Expand All @@ -86,13 +93,6 @@ Item {
height: parent.height * 0.5
fillMode: Image.PreserveAspectFit

/* MouseArea {
anchors.fill: parent
onClicked: {editthis.field = "Title"
editthis.where = "lesson"
editthis.itemId = lessonNumber
editthis.state = "Active" }
} */
}
}

Expand Down Expand Up @@ -151,7 +151,14 @@ Item {
height: width
fillMode: Image.PreserveAspectCrop
visible: false
source: "../icons/frontC.png"
source: IPFS.grabImage(userCode,"profile")

Image {
anchors.fill: parent
fillMode: Image.PreserveAspectCrop
source:"/icons/frontC.png"
z:-1
}
}
OpacityMask {
source: profileImage
Expand All @@ -161,7 +168,10 @@ Item {

MouseArea {
anchors.fill: parent
onClicked: files.visible = true
onClicked: {
files.type = "profile"
files.visible = true
}
}
}

Expand Down Expand Up @@ -351,5 +361,7 @@ Item {

Files {
id:files
type:"profile"
onVisibleChanged: if(visible === false) {files.clearSelection()}
}
}
6 changes: 6 additions & 0 deletions Desktop/General/general.js
Expand Up @@ -28,6 +28,11 @@ guidingQuestions MEDIUMTEXT, lessonSequence MEDIUMTEXT, studentProduct MEDIUMTEX
'CREATE TABLE IF NOT EXISTS Student_Assignments (schoolCode TEXT, studentCode MEDIUMINT, lessonID MEDIUMINT, status INT, qaList MEDIUMTEXT, creationdate MEDIUMINT, editdate MEDIUMINT)')
tx.executeSql(
'CREATE TABLE IF NOT EXISTS Student_Daily_Review (schoolCode TEXT,studentCode MEDIUMINT,qaList MEDIUMTEXT, date MEDIUMINT )')

/* Media databases */

tx.executeSql(
'CREATE TABLE IF NOT EXISTS Media (schoolCode TEXT,owner TEXT,type TEXT,filename TEXT,hash TEXT,creationdate MEDIUMINT)')
})
}

Expand Down Expand Up @@ -151,6 +156,7 @@ function loadprofile(userid) {
userCountry = pull.rows.item(0).country
userState = pull.rows.item(0).state
userEditDate = pull.rows.item(0).editdate
userCode = pull.rows.item(0).code
}

if (pull1.rows.length === 1) {
Expand Down
67 changes: 67 additions & 0 deletions Desktop/General/ipfs.js
@@ -0,0 +1,67 @@
function mediaAdd(file,type) {

//console.log("adding things " + file)
var ipfsReference = file.toString().split(" ")


var returned = "http://localhost:8080/ipfs/"+ipfsReference[1]

db.transaction(function (tx) {

var dataSTR = "INSERT INTO Media VALUES(?,?,?,?,?,?)"
var data = [schoolCode, userCode, type,ipfsReference[2], ipfsReference[1], d.getTime(
)]

var check = tx.executeSql(
"SELECT * from Media WHERE hash = '" + ipfsReference[1] + "'")

if (check.rows.length !== 1) {
tx.executeSql(dataSTR, data)
}
})

return returned
}

function mediaRetrieve(hash) {

db.readTransaction(function (tx) {

var check = tx.executeSql(
"SELECT * from Media WHERE hash = '" + hash + "'")

if (check.rows.length === 1) {

}
})

}

function grabImage(userCode,type) {

/* checks for existence of an image based on what and who owns it, instead of a hash and returns the ipfs url */

var returned = ""

db.readTransaction(function (tx) {

var check = tx.executeSql(
"SELECT * from Media WHERE owner = '"+userCode+"' AND type = '" + type + "' ORDER BY creationdate DESC")

if(check.rows.length !==0) {
switch(type) {
case "profile":returned = "http://localhost:8080/ipfs/"+check.rows.item(0).hash
break
case "general":returned = "http://localhost:8080/ipfs/"+check.rows.item(0).hash
break

}
} else {
console.log("no image found")
}

})

return returned
}

6 changes: 4 additions & 2 deletions Desktop/General/network.js
Expand Up @@ -223,8 +223,6 @@ function retrieveFromOpenSeed(id, code, type, update) {

var info = http.responseText.split(";&;")



db.transaction(function (tx) {

switch (type) {
Expand Down Expand Up @@ -454,3 +452,7 @@ function sync(type, code) {
+ "&code=" + code + "&type=" + type)
gc()
}




2 changes: 2 additions & 0 deletions Desktop/main.cpp
Expand Up @@ -5,13 +5,15 @@
#include <QQmlApplicationEngine>

#include "./io.h"
#include "./process.h"


int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

qmlRegisterType<IOout>("IO", 1, 0, "IOout");
qmlRegisterType<Process>("Process", 1, 0, "Process");

QApplication app(argc, argv);

Expand Down

0 comments on commit 6ddcf57

Please sign in to comment.