-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_activity.py
301 lines (231 loc) · 10.6 KB
/
project_activity.py
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'project_activity.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
from dialogs import Dialog
import mysql.connector
from db import con
import datetime
from PyQt5.QtCore import QDate, Qt
class Ui_Activity(object):
TBLActivity = "" # Activity Log table
activity_filter = "" # Activity Combo Box
def record_activity(user,action):
try:
now = datetime.datetime.now()
time = now.strftime("%m/%d/%Y - %H:%M")
query1 = "INSERT INTO activity(Act_desc, Act_time,Act_user) VALUES (%s,%s,%s)"
query2 = (action,time,user)
cursor = con.cursor()
cursor.execute(query1, query2)
con.commit()
except:
Dialog.msg_dialog("Server Error Please Try Again")
def process_date2(bday):
index = 0
start = 0
flag1 = True
flag2 = False
flag3 = False
while index < len(bday):
if flag1 and (bday[index] == "/"):
year = bday[start:index]
start = index + 1
flag1 = False
flag2 = True
elif flag2 and (bday[index] == "/"):
month = bday[start:index]
start = index + 1
flag2 = False
flag3 = True
if flag3:
day = bday[start:len(bday)]
break
index = index + 1
return QDate(int(day), int(year), int(month))
def insert_activity():
# Remove Rows
while(Ui_Activity.TBLActivity.rowCount() > 0):
Ui_Activity.TBLActivity.removeRow(0)
#Font Properties
font = QtGui.QFont()
font.setFamily("Calibri")
font.setPointSize(12)
font.setBold(False)
#Array initialization (4) Elements
db = ['','','','']
cursor = con.cursor()
cursor.execute("SELECT * FROM `activity` ORDER BY `Act_id` DESC")
res = cursor.fetchall()
row_count = len(res); # based on DB Rows -- End Point of Loop
Ui_Activity.TBLActivity.setRowCount(row_count) # based on DB Rows
index = 0
for x in res:
# x (Row Number)
#fetch values and store in array
db[0] = x[2][0:10] # date
db[1] = x[2][13:len(x[2])] # time
db[2] = x[1] # user
db[3] = x[3] # description
if db[2].isnumeric():
db[2] ="Open Project id: "+str(db[2])
# insert data cell by cell
for i in range(0,4):
# i (Column Number)
item = QtWidgets.QTableWidgetItem()
item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
Ui_Activity.TBLActivity.setItem(index, i, item)
#set Text
item.setFont(font)
item.setTextAlignment(QtCore.Qt.AlignCenter)
item = Ui_Activity.TBLActivity.item(index, i)
item.setText(db[i])
index = index + 1 # Another Row
def filterAct():
# Remove Rows
while(Ui_Activity.TBLActivity.rowCount() > 0):
Ui_Activity.TBLActivity.removeRow(0)
search = Ui_Activity.activity_filter.currentText()
if search=="All":
Ui_Activity.insert_activity()
else:
#Font Properties
font = QtGui.QFont()
font.setFamily("Calibri")
font.setPointSize(12)
font.setBold(False)
#Array initialization (4) Elements
row=[]
cursor = con.cursor()
cursor.execute("SELECT * FROM `activity` ORDER BY `Act_id` DESC ")
res = cursor.fetchall()
for x in res:
# x (Row Number)
#fetch values and store in array
dd=x[2][0:10]
date = Ui_Activity.process_date2(dd)
now = QDate.currentDate()
db = ['','','','']
if search=="Yesterday":
now=now.addDays(-1)
if date==now:
db[0] = x[2][0:10] # date
db[1] = x[2][13:len(x[2])] # time
db[2] = x[1] # user
db[3] = x[3] # description
if db[2].isnumeric():
db[2] ="Open Project id: "+str(db[2])
row.append(db)
if search=="Today":
now = QDate.currentDate()
if date==now:
db[0] = x[2][0:10] # date
db[1] = x[2][13:len(x[2])] # time
db[2] = x[1] # user
db[3] = x[3] # description
if db[2].isnumeric():
db[2] ="Open Project id: "+str(db[2])
row.append(db)
if search=="Older":
now=now.addDays(-1)
if date<now:
db[0] = x[2][0:10] # date
db[1] = x[2][13:len(x[2])] # time
db[2] = x[1] # user
db[3] = x[3] # description
if db[2].isnumeric():
db[2] ="Open Project id: "+str(db[2])
row.append(db)
Ui_Activity.TBLActivity.setRowCount(len(row)) # based on DB Rows
# insert data cell by cell
index=0
for j in row:
for i in range(0,4):
# i (Column Number)
item = QtWidgets.QTableWidgetItem()
item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
Ui_Activity.TBLActivity.setItem(index, i, item)
#set Text
item.setFont(font)
item.setTextAlignment(QtCore.Qt.AlignCenter)
item = Ui_Activity.TBLActivity.item(index, i)
item.setText(row[index][i])
index=index+1
def Activity(ActivityPage):
#Font Properties
font = QtGui.QFont()
font.setFamily("Calibri")
font.setPointSize(24)
font.setBold(True)
font.setWeight(75)
# Activity Log (Title)
LBActivity = QtWidgets.QLabel(ActivityPage)
LBActivity.setGeometry(QtCore.QRect(30, 20, 621, 51))
LBActivity.setFont(font)
LBActivity.setStyleSheet("color:white;background:QLinearGradient( x1: 0, y1: 0, x2: 1,y2:0, stop: 0 rgb(255,0,0,.4),stop:1 transparent);padding-left:15px;")
LBActivity.setObjectName("LBActivity")
# Activity Widget
Activity = QtWidgets.QGroupBox(ActivityPage)
Activity.setGeometry(QtCore.QRect(30, 100, 1011, 411))
Activity.setStyleSheet("border:none;color:white;")
Activity.setObjectName("Activity")
# BG Activity Log
BGActivity = QtWidgets.QLabel(Activity)
BGActivity.setGeometry(QtCore.QRect(0, 0, 1011, 411))
BGActivity.setStyleSheet("background-color: rgb(255,0,0,.4);border-radius:8px;")
BGActivity.setObjectName("BGActivity")
# Table Activity Log
font.setPointSize(12)
Ui_Activity.TBLActivity = QtWidgets.QTableWidget(Activity)
Ui_Activity.TBLActivity.setGeometry(QtCore.QRect(10, 10, 991, 391))
Ui_Activity.TBLActivity.setFont(font)
Ui_Activity.TBLActivity.setStyleSheet("QTableWidget{background-color: rgb(48, 0, 2,.5);border:1px solid white;}QTableWidget::item{;border:1px solid white;}")
Ui_Activity.TBLActivity.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
Ui_Activity.TBLActivity.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
Ui_Activity.TBLActivity.setObjectName("TBLActivity")
Ui_Activity.TBLActivity.setColumnCount(4) # Default 4 Column
Ui_Activity.TBLActivity.horizontalHeader().setVisible(True)
Ui_Activity.TBLActivity.horizontalHeader().setDefaultSectionSize(150)
Ui_Activity.TBLActivity.horizontalHeader().setHighlightSections(True)
Ui_Activity.TBLActivity.verticalHeader().setVisible(False)
Ui_Activity.TBLActivity.verticalHeader().setHighlightSections(True)
font = QtGui.QFont()
font.setFamily("Calibri")
font.setPointSize(12)
activity_label = QtWidgets.QLabel(ActivityPage)
activity_label.setGeometry(QtCore.QRect(805,30, 80, 31))
activity_label.setFont(font)
activity_label.setStyleSheet("color: rgb(255, 255, 255);")
activity_label.setObjectName("activity_label")
activity_label.setText("Filter By:")
ActivityPage.setStyleSheet("color:white;")
Ui_Activity.activity_filter = QtWidgets.QComboBox(ActivityPage)
Ui_Activity.activity_filter.setGeometry(QtCore.QRect(885, 30, 150, 31))
Ui_Activity.activity_filter.setFont(font)
Ui_Activity.activity_filter.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
Ui_Activity.activity_filter.setStyleSheet("QComboBox{color: rgb(255, 255, 255);background-color: rgba(255,255,255,.2);border-radius:5px;}")
Ui_Activity.activity_filter.setObjectName("activity_filter")
Ui_Activity.activity_filter.addItem("All")
Ui_Activity.activity_filter.addItem("Today")
Ui_Activity.activity_filter.addItem("Yesterday")
Ui_Activity.activity_filter.addItem("Older")
Ui_Activity.activity_filter.activated.connect(Ui_Activity.filterAct)
# Set Text Default
LBActivity.setText("Activity Log")
# Header Activity Table
font.setBold(True)
font.setPointSize(16)
hheader = ['Date','Time','Description','User',]
Ui_Activity.TBLActivity.horizontalHeader().setStyleSheet('''::section{background-color:transparent;border:1px solid white;width:500px;height:40px;}''')
for x in range(0,4):
item = QtWidgets.QTableWidgetItem()
Ui_Activity.TBLActivity.setHorizontalHeaderItem(x, item)
item = Ui_Activity.TBLActivity.horizontalHeaderItem(x)
item.setFont(font)
item.setText(hheader[x])
# Table Properties
Ui_Activity.TBLActivity.setColumnWidth(2,523)