-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPushScreen.lua
More file actions
152 lines (133 loc) · 4.6 KB
/
PushScreen.lua
File metadata and controls
152 lines (133 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
-- PushScreen.lua
PushScreen = class(AppleScreen)
function PushScreen:init(repo,proj,repoFiles,projFiles,prevScreen)
self.projFiles = projFiles
self.repoFiles = repoFiles
self.repo = repo
self.proj = proj
self.toPush = self:filesToPush()
self.fileElems = {}
local schema = {
title = "Push",
backButton = {
text = prevScreen.schema.title,
callback = function() screen = prevScreen end,
},
elems = {
{type="block",elems = {
{type="TextInput",label="Password",protected=true,tag="password"}
}},
{type="blank",amount=20},
{type="text",text="Commit message"},
{type="blank",amount=5},
{type="MultiTextInput",lines = 5,tag="commit"},
{type="blank",amount=20},
{type="block",elems = {
{type="SimpleArrow",text="OK",callback=function() self:pushIt() end,
tag="OK"},
}},
{type="blank",amount=20},
{type="selector",elems=self.fileElems}
}
}
local addedFiles = {}
local removedFiles = {}
local changedFiles = {}
for file,changeType in pairs(self.toPush) do
if changeType == "Added" then table.insert(addedFiles,file)
elseif changeType == "Removed" then table.insert(removedFiles,file)
else -- changed
table.insert(changedFiles,file)
end
end
table.sort(addedFiles)
table.sort(removedFiles)
table.sort(changedFiles)
for _,file in ipairs(addedFiles) do
table.insert(self.fileElems,{text=file,tag="file"..file})
end
for _,file in ipairs(changedFiles) do
table.insert(self.fileElems,{text=file,tag="file"..file})
end
for _,file in ipairs(removedFiles) do
table.insert(self.fileElems,{text=file,tag="file"..file})
end
AppleScreen.init(self,schema)
-- toggle each file as selected
for file,changeType in pairs(self.toPush) do
local selector = self.taggedElems["file"..file]
selector.selected = true
selector:setRightText(changeType)
if changeType == "Added" then
selector:setColors(color(0,0,255),color(0,0,255))
elseif changeType == "Removed" then
selector:setColors(color(255,0,0),color(255,0,0))
else -- changeType should be Changed
selector:setColors(color(255,255,0),color(255,255,0))
end
end
end
function PushScreen:pushIt()
-- retrieve the password
local passBox = self.taggedElems.password.textbox
local password = passBox.text
-- retrieve the commit message
local msg = self.taggedElems.commit.textbox.text
if msg:len() == 0 then
msg = "uploaded from codea's "..self.proj
end
-- retrieve the list of files
local changedFiles = {}
local removedFiles = {}
for file,changeType in pairs(self.toPush) do
local selector = self.taggedElems["file"..file]
if selector.selected then
if self.projFiles[file] then
changedFiles[file] = self.projFiles[file]
else
table.insert(removedFiles,file)
end
end
end
--[[
print("changedfiles")
for file,c in pairs(changedFiles) do print(file) end
print("removedFiles")
for _,f in ipairs(removedFiles) do print(f) end
--assert(false)
--]]
self.taggedElems["OK"]:showHourGlass(true)
self.active = false -- we'll wait for thee http request
local commitcb = function(info)
self.active = true
self.taggedElems["OK"]:showHourGlass(false)
self.taggedElems["OK"]:setRightText("Success")
GIT_CLIENT:removePassword()
end
local failcb = function(err)
self.active = true
self.taggedElems["OK"]:showHourGlass(false)
self.taggedElems["OK"]:setRightText("FAILED")
GIT_CLIENT:removePassword()
print("ERROR:\n",err)
end
GIT_CLIENT:setReponame(self.repo)
GIT_CLIENT:setPassword(password)
GIT_CLIENT:commit(changedFiles,removedFiles,msg,commitcb,failcb)
end
function PushScreen:filesToPush()
local toPush = {}
for file,projConts in pairs(self.projFiles) do
if self.repoFiles[file] == nil then
toPush[file]="Added"
elseif self.repoFiles[file] ~= projConts then
toPush[file]="Changed"
end
end
for file,repoConts in pairs(self.repoFiles) do
if self.projFiles[file] == nil then
toPush[file]="Removed"
end
end
return toPush
end