Intial work on projects view
This commit is contained in:
parent
7e9553eeca
commit
ad6a8a4e3c
@ -8,7 +8,7 @@ FONT_LARGE = ("Verdana", 20)
|
||||
URL = "http://localhost:8000/api/authenticate"
|
||||
URL_REGISTER = "http://localhost:8000/api/register"
|
||||
URL_PROFILE = "http://localhost:8000/api/profile"
|
||||
|
||||
URL_PROJECTS = "http://localhost:8000/api/projects"
|
||||
|
||||
class SmartPicasso(tk.Tk):
|
||||
|
||||
@ -95,7 +95,7 @@ class MainView(tk.Frame):
|
||||
tk.Frame.__init__(self, parent)
|
||||
self.frames = {}
|
||||
self.token = ''
|
||||
for F in (ProfileView,):
|
||||
for F in (ProfileView, ProjectsView, ProjectsAddView):
|
||||
frame = F(parent, controller)
|
||||
|
||||
self.frames[F] = frame
|
||||
@ -105,11 +105,21 @@ class MainView(tk.Frame):
|
||||
label.pack(pady=10, padx=10)
|
||||
label_u = tk.Label(self, text="Main menu", font=FONT)
|
||||
label_u.pack(pady=10, padx=10)
|
||||
|
||||
button_projects = tk.Button(self, text="Projects", font=FONT,
|
||||
command=lambda: self.show_frame(ProjectsView))
|
||||
button_projects.pack()
|
||||
|
||||
button_projects2 = tk.Button(self, text="Projects Add", font=FONT,
|
||||
command=lambda: self.show_frame(ProjectsAddView))
|
||||
button_projects2.pack()
|
||||
|
||||
|
||||
button_profile = tk.Button(self, text="My profile", font=FONT,
|
||||
command=lambda: self.show_frame(ProfileView))
|
||||
button_profile.pack()
|
||||
|
||||
|
||||
def show_frame(self, view):
|
||||
frame = self.frames[view]
|
||||
frame.tkraise()
|
||||
@ -223,6 +233,72 @@ class ProfileView(tk.Frame):
|
||||
self.label_first_name['text'] = response['profile']['first_name']
|
||||
self.label_last_name['text'] = response['profile']['last_name']
|
||||
|
||||
class ProjectsView(tk.Frame):
|
||||
|
||||
def __init__(self, parent, controller):
|
||||
tk.Frame.__init__(self, parent)
|
||||
self.token = ''
|
||||
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
|
||||
label.pack(pady=10, padx=10)
|
||||
button_add = tk.Button(self, text="Add project", font=FONT,
|
||||
command=lambda: controller.show_frame(ProjectsAddView, self.token))
|
||||
button_add.pack()
|
||||
|
||||
button_back = tk.Button(self, text="Back", font=FONT,
|
||||
command=lambda: controller.show_frame(MainView, self.token))
|
||||
button_back.pack()
|
||||
label0 = tk.Label(self, text='Projects:', font=FONT)
|
||||
label0.pack()
|
||||
|
||||
def start(self):
|
||||
headers = {'Authorization': 'Bearer ' + self.token}
|
||||
resp = requests.get(URL_PROJECTS, headers=headers)
|
||||
response = resp.json()
|
||||
print(response)
|
||||
for projects in response:
|
||||
button_proj = tk.Button(self, text=projects['name'], font=FONT)
|
||||
button_proj.pack()
|
||||
|
||||
class ProjectsAddView(tk.Frame):
|
||||
|
||||
def __init__(self, parent, controller):
|
||||
tk.Frame.__init__(self, parent)
|
||||
self.token = ''
|
||||
|
||||
label0 = tk.Label(self, text='Project name:', font=FONT)
|
||||
label0.pack()
|
||||
|
||||
input0 = tk.Entry(self)
|
||||
input0.pack()
|
||||
|
||||
button_add = tk.Button(self, text="Confirm and add", font=FONT,
|
||||
command=lambda: self.addproject(controller, input0.get()))
|
||||
button_add.pack()
|
||||
|
||||
button_back = tk.Button(self, text="Back", font=FONT,
|
||||
command=lambda: controller.show_frame(ProjectsView))
|
||||
button_back.pack()
|
||||
|
||||
def start(self):
|
||||
print("ok")
|
||||
|
||||
def addproject(self, controller, projectname):
|
||||
headers = {'Authorization': 'Bearer ' + self.token}
|
||||
data = {
|
||||
"name": str(projectname)
|
||||
}
|
||||
print(data)
|
||||
response = requests.post(URL_PROJECTS, json=data, headers=headers)
|
||||
print(response)
|
||||
if response.status_code == 201:
|
||||
response = response.json()
|
||||
controller.show_frame(MainView)
|
||||
else:
|
||||
print("sth wrong")
|
||||
bad_pass_label = tk.Label(self, text='Something went wrong!', font=FONT)
|
||||
bad_pass_label.pack()
|
||||
return ()
|
||||
|
||||
|
||||
app = SmartPicasso()
|
||||
app.mainloop()
|
||||
|
Loading…
Reference in New Issue
Block a user