SMART-18 Merge pull request 'projects_view' (#9) from projects_view into develop

Reviewed-on: #9
This commit is contained in:
Patryk Dolata 2020-12-21 14:25:18 +01:00
commit 86afc9b2f8
5 changed files with 81 additions and 3 deletions

View File

@ -8,6 +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,8 +96,8 @@ class MainView(tk.Frame):
tk.Frame.__init__(self, parent)
self.frames = {}
self.token = ''
for F in (ProfileView,):
frame = F(parent, controller)
for F in (ProfileView, ProjectsView, ProjectsAddView):
frame = F(parent, controller, self)
self.frames[F] = frame
@ -106,6 +107,10 @@ class MainView(tk.Frame):
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_profile = tk.Button(self, text="My profile", font=FONT,
command=lambda: self.show_frame(ProfileView))
button_profile.pack()
@ -192,7 +197,7 @@ class RegisterView(tk.Frame):
class ProfileView(tk.Frame):
def __init__(self, parent, controller):
def __init__(self, parent, controller, main_view_controller):
tk.Frame.__init__(self, parent)
self.token = ''
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
@ -224,5 +229,78 @@ class ProfileView(tk.Frame):
self.label_last_name['text'] = response['profile']['last_name']
class ProjectsView(tk.Frame):
def __init__(self, parent, controller, main_view_controller):
tk.Frame.__init__(self, parent)
self.token = ''
self.projects_buttons = []
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: main_view_controller.show_frame(ProjectsAddView))
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):
for button in self.projects_buttons:
button.destroy()
self.projects_buttons = []
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()
self.projects_buttons.append(button_proj)
class ProjectsAddView(tk.Frame):
def __init__(self, parent, controller, main_view_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.add_project(main_view_controller, input0.get()))
button_add.pack()
button_back = tk.Button(self, text="Back", font=FONT,
command=lambda: main_view_controller.show_frame(ProjectsView))
button_back.pack()
def start(self):
print("ok")
def add_project(self, controller, project_name):
headers = {'Authorization': 'Bearer ' + self.token}
data = {
"name": str(project_name)
}
print(data)
response = requests.post(URL_PROJECTS, json=data, headers=headers)
print(response)
if response.status_code == 201:
response = response.json()
controller.show_frame(ProjectsView)
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()

Binary file not shown.