notification feature
This commit is contained in:
parent
c13b86c031
commit
baaa1d052a
|
@ -65,6 +65,7 @@
|
||||||
<!--<th class="uk-table-shrink"></th>-->
|
<!--<th class="uk-table-shrink"></th>-->
|
||||||
<th class="uk-table-expand cm-text-muted">Profile</th>
|
<th class="uk-table-expand cm-text-muted">Profile</th>
|
||||||
<th class="uk-table-small cm-text-muted">Modified</th>
|
<th class="uk-table-small cm-text-muted">Modified</th>
|
||||||
|
<th class="uk-table-small cm-text-muted">Notified <span class="cm-tooltip" uk-icon="icon: info" title="When your profile is in its final version, notify the OpenAIRE Mining experts to process it" uk-tooltip="pos: right"></span></th>
|
||||||
<th class="uk-width-small cm-text-muted">Status</th>
|
<th class="uk-width-small cm-text-muted">Status</th>
|
||||||
<!--<th class="uk-table-shrink uk-text-nowrap">Matches</th>-->
|
<!--<th class="uk-table-shrink uk-text-nowrap">Matches</th>-->
|
||||||
<th></th>
|
<th></th>
|
||||||
|
@ -96,6 +97,11 @@
|
||||||
<a class="uk-link-reset" (click)="loadSavedProfile(profile.id, profile.name)">{{profile.name}}</a>
|
<a class="uk-link-reset" (click)="loadSavedProfile(profile.id, profile.name)">{{profile.name}}</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="cm-text-muted uk-text-nowrap">{{profile.datecreated}}</td>
|
<td class="cm-text-muted uk-text-nowrap">{{profile.datecreated}}</td>
|
||||||
|
<td class="cm-text-muted uk-text-nowrap">
|
||||||
|
<button *ngIf="!profile.notified && !pending" class="uk-button uk-button-secondary uk-button-small uk-text-center cm-margin" (click)="notifyProfile(profile)">Notify</button>
|
||||||
|
<button *ngIf="pending" class="uk-button uk-button-secondary uk-button-small uk-text-center cm-margin" disabled>Notifing... <span uk-spinner="ratio: 0.8"></span></button>
|
||||||
|
<span *ngIf="profile.notified " class="uk-label uk-label-success">Notified</span>
|
||||||
|
</td>
|
||||||
<td class="uk-text-nowrap uk-text-warning">{{profile.status}}</td>
|
<td class="uk-text-nowrap uk-text-warning">{{profile.status}}</td>
|
||||||
<!--<td class="uk-text-nowrap">{{profile.matches}}</td>-->
|
<!--<td class="uk-text-nowrap">{{profile.matches}}</td>-->
|
||||||
<td class="delete">
|
<td class="delete">
|
||||||
|
|
|
@ -19,10 +19,12 @@ export class ManageprofilesComponent implements OnInit {
|
||||||
|
|
||||||
public allUsersProfiles: Array<UsersMetadata> = [];
|
public allUsersProfiles: Array<UsersMetadata> = [];
|
||||||
public statusValues = [
|
public statusValues = [
|
||||||
'Saved',
|
'Processing',
|
||||||
'Evaluating',
|
'Evaluating',
|
||||||
'On Beta'
|
'On Beta'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public communityId = '';
|
||||||
public isCommunityManager = false;
|
public isCommunityManager = false;
|
||||||
|
|
||||||
public userSavedProfiles: Array<ProfileMetadata> = [];
|
public userSavedProfiles: Array<ProfileMetadata> = [];
|
||||||
|
@ -34,6 +36,8 @@ export class ManageprofilesComponent implements OnInit {
|
||||||
currentPage: 1
|
currentPage: 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public pending = false;
|
||||||
|
|
||||||
constructor(private manageProfilesService: ManageprofilesService, private route: ActivatedRoute, private router: Router) {
|
constructor(private manageProfilesService: ManageprofilesService, private route: ActivatedRoute, private router: Router) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +45,9 @@ export class ManageprofilesComponent implements OnInit {
|
||||||
this.route.queryParams
|
this.route.queryParams
|
||||||
.subscribe(
|
.subscribe(
|
||||||
params => {
|
params => {
|
||||||
console.log('queryParams', params['communityId']);
|
// console.log('queryParams', params['communityId']);
|
||||||
this.initialServerhandshake(params['communityId']);
|
this.communityId = params['communityId'];
|
||||||
|
this.initialServerhandshake(this.communityId);
|
||||||
});
|
});
|
||||||
this.isCommunityManager = this.manageProfilesService.isCommunityManager === 'true';
|
this.isCommunityManager = this.manageProfilesService.isCommunityManager === 'true';
|
||||||
}
|
}
|
||||||
|
@ -193,6 +198,18 @@ export class ManageprofilesComponent implements OnInit {
|
||||||
.subscribe(res => this.exampleProfiles = res);
|
.subscribe(res => this.exampleProfiles = res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notifyProfile(profile: ProfileMetadata ): void {
|
||||||
|
UIkit.modal.confirm('<span class="uk-text-bold">' +
|
||||||
|
'A notification will be sent to the OpenAIRE Mining experts, that your profile is in its final version!</br></br>Are you sure you want to proceed?</span>', {escClose: true}).then(() => {
|
||||||
|
this.pending = true;
|
||||||
|
this.manageProfilesService.notifyProfile(this.communityId, profile.id)
|
||||||
|
.subscribe(res => {
|
||||||
|
profile.notified = 1;
|
||||||
|
this.pending = false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
loadExampleProfile(name: string): void {
|
loadExampleProfile(name: string): void {
|
||||||
// clear localstorage values
|
// clear localstorage values
|
||||||
this.clearLocalStorage();
|
this.clearLocalStorage();
|
||||||
|
|
|
@ -27,6 +27,7 @@ export class ManageprofilesService {
|
||||||
private getExampleProfilesUrl = '/getexampleprofiles';
|
private getExampleProfilesUrl = '/getexampleprofiles';
|
||||||
private loadExampleProfileUrl = '/loadexampleprofile';
|
private loadExampleProfileUrl = '/loadexampleprofile';
|
||||||
private uploadProfileUrl = '/uploadprofile';
|
private uploadProfileUrl = '/uploadprofile';
|
||||||
|
private notifyProfileUrl = '/notifyforprofile';
|
||||||
|
|
||||||
constructor(private http: HttpClient) {
|
constructor(private http: HttpClient) {
|
||||||
this.userId = this.util.getUserId();
|
this.userId = this.util.getUserId();
|
||||||
|
@ -114,4 +115,9 @@ export class ManageprofilesService {
|
||||||
.catch(this.util.handleError);
|
.catch(this.util.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notifyProfile(communityId: string, profileId: string): Observable<any> {
|
||||||
|
return this.http.post(this.backendServerAddress + this.notifyProfileUrl, {community: communityId, user: this.userId, id: profileId})
|
||||||
|
.catch(this.util.handleError);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,5 +4,6 @@ export class ProfileMetadata {
|
||||||
datecreated: string;
|
datecreated: string;
|
||||||
status: string;
|
status: string;
|
||||||
matches: string;
|
matches: string;
|
||||||
|
notified: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,8 @@ class Application(tornado.web.Application):
|
||||||
(r"/runmining", RunMiningHandler),
|
(r"/runmining", RunMiningHandler),
|
||||||
(r"/preparesavedprofile", PrepareSavedProfileHandler),
|
(r"/preparesavedprofile", PrepareSavedProfileHandler),
|
||||||
(r"/saveprofile", SaveProfileToDatabaseHandler),
|
(r"/saveprofile", SaveProfileToDatabaseHandler),
|
||||||
(r"/downloadprofile", DownloadProfileHandler)
|
(r"/downloadprofile", DownloadProfileHandler),
|
||||||
|
(r"/notifyforprofile", NotifyHandler)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -467,8 +468,8 @@ class GetUsersProfilesHandler(BaseHandler):
|
||||||
except Exception as ints:
|
except Exception as ints:
|
||||||
print ints
|
print ints
|
||||||
community_id = 'Unkown '+user
|
community_id = 'Unkown '+user
|
||||||
for r in cursor.execute('''SELECT id,name,datecreated,status,matches,docname FROM database order by rowid desc'''):
|
for r in cursor.execute('''SELECT id,name,datecreated,status,matches,docname,notified FROM database order by rowid desc'''):
|
||||||
users_profiles.append({"user":community_id,"userId":user,"profileId":r[0], "profile": r[1], "datecreated": r[2], "status": r[3], "matches": r[4], "docname": r[5]})
|
users_profiles.append({"user":community_id,"userId":user,"profileId":r[0], "profile": r[1], "datecreated": r[2], "status": r[3], "matches": r[4], "docname": r[5], "notified": r[6] })
|
||||||
data['profiles'] = users_profiles
|
data['profiles'] = users_profiles
|
||||||
self.write(json.dumps(data))
|
self.write(json.dumps(data))
|
||||||
self.finish()
|
self.finish()
|
||||||
|
@ -513,7 +514,7 @@ class UpdateProfileStatusHandler(BaseHandler):
|
||||||
cursor=madis.functions.Connection(database_file_name).cursor()
|
cursor=madis.functions.Connection(database_file_name).cursor()
|
||||||
# Write new Profile status to users database
|
# Write new Profile status to users database
|
||||||
status = request_arguments['status']
|
status = request_arguments['status']
|
||||||
cursor.execute('''UPDATE database set status=? where id=?''', (profile_id,status,), parse=False)
|
cursor.execute('''UPDATE database set status=? where id=?''', (status,profile_id,), parse=False)
|
||||||
cursor.close()
|
cursor.close()
|
||||||
self.write(json.dumps({}))
|
self.write(json.dumps({}))
|
||||||
self.finish()
|
self.finish()
|
||||||
|
@ -560,8 +561,8 @@ class GetUserProfilesHandler(BaseHandler):
|
||||||
# data to be sent
|
# data to be sent
|
||||||
data = {}
|
data = {}
|
||||||
user_profiles = []
|
user_profiles = []
|
||||||
for r in cursor.execute('''SELECT id,name,datecreated,status,matches,docname FROM database order by rowid desc'''):
|
for r in cursor.execute('''SELECT id,name,datecreated,status,matches,docname,notified FROM database order by rowid desc'''):
|
||||||
user_profiles.append({"id":r[0], "name": r[1], "datecreated": r[2], "status": r[3], "matches": r[4], "docname": r[5]})
|
user_profiles.append({"id":r[0], "name": r[1], "datecreated": r[2], "status": r[3], "matches": r[4], "docname": r[5], "notified": r[6]})
|
||||||
data['profiles'] = user_profiles
|
data['profiles'] = user_profiles
|
||||||
cursor.close()
|
cursor.close()
|
||||||
self.write(json.dumps(data))
|
self.write(json.dumps(data))
|
||||||
|
@ -1603,9 +1604,9 @@ class SaveProfileToDatabaseHandler(BaseHandler):
|
||||||
cursor=madis.functions.Connection(database_file_name).cursor()
|
cursor=madis.functions.Connection(database_file_name).cursor()
|
||||||
user_profiles = []
|
user_profiles = []
|
||||||
if old_profile:
|
if old_profile:
|
||||||
cursor.execute('''UPDATE database SET datecreated=?, status=?, matches=?, docname=?, docsnumber=? WHERE id=?''', (datetime.date.today().strftime("%B %d %Y"),"Ready","8/8",doc_name,docs_number,profile_id), parse=False)
|
cursor.execute('''UPDATE database SET datecreated=?, status=?, matches=?, docname=?, docsnumber=?, notified=? WHERE id=?''', (datetime.date.today().strftime("%B %d %Y"),"Processing","8/8",doc_name,docs_number,0,profile_id), parse=False)
|
||||||
else:
|
else:
|
||||||
cursor.execute('''INSERT INTO database VALUES(?,?,?,?,?,?,?)''', (profile_id,profile_name,datetime.date.today().strftime("%B %d %Y"),"Saved","8/8",doc_name,docs_number,), parse=False)
|
cursor.execute('''INSERT INTO database VALUES(?,?,?,?,?,?,?,?)''', (profile_id,profile_name,datetime.date.today().strftime("%B %d %Y"),"Saved","8/8",doc_name,docs_number,0,), parse=False)
|
||||||
cursor.close()
|
cursor.close()
|
||||||
self.write(json.dumps({}))
|
self.write(json.dumps({}))
|
||||||
self.finish()
|
self.finish()
|
||||||
|
@ -1659,6 +1660,66 @@ class DownloadProfileHandler(BaseHandler):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
class NotifyHandler(BaseHandler):
|
||||||
|
passwordless=True
|
||||||
|
def set_default_headers(self):
|
||||||
|
self.set_header("Access-Control-Allow-Origin", "*")
|
||||||
|
self.set_header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
|
||||||
|
self.set_header('Access-Control-Allow-Methods', 'POST, OPTIONS')
|
||||||
|
self.set_header('Access-Control-Allow-Credentials', 'true')
|
||||||
|
self.set_header('Content-Type', 'application/oamp')
|
||||||
|
def options(self):
|
||||||
|
# no body
|
||||||
|
self.set_status(204)
|
||||||
|
self.finish()
|
||||||
|
def post(self):
|
||||||
|
try:
|
||||||
|
# get user id from body. Must have
|
||||||
|
request_arguments = json.loads(self.request.body)
|
||||||
|
if 'user' not in request_arguments or request_arguments['user'] == '':
|
||||||
|
self.set_status(400)
|
||||||
|
self.write("Missing user's id argument")
|
||||||
|
return
|
||||||
|
community = request_arguments['community'][:128]
|
||||||
|
user_id = request_arguments['user'][:128]
|
||||||
|
# get data
|
||||||
|
profile_id = request_arguments['id'][:128]
|
||||||
|
# Import smtplib for the actual sending function
|
||||||
|
import smtplib
|
||||||
|
subject = 'New Profile update of Community: {} on profile: {}'.format(community, profile_id)
|
||||||
|
text = 'Hello our great mining team experts of OpenAIRE,\n\nA new profile update of Community {}\non profile named: {}'.format(community, profile_id)
|
||||||
|
message = 'Subject: {}\n\n{}'.format(subject, text)
|
||||||
|
# Send the message via our own SMTP server.
|
||||||
|
s = smtplib.SMTP(msettings.SMTP_HOST, msettings.SMTP_PORT)
|
||||||
|
s.ehlo()
|
||||||
|
s.starttls()
|
||||||
|
s.ehlo()
|
||||||
|
s.login(msettings.SMTP_USERNAME, msettings.SMTP_PASSWORD)
|
||||||
|
s.sendmail(msettings.SMTP_FROM, 'sospioneer2002@gmail.com', message)
|
||||||
|
s.quit()
|
||||||
|
|
||||||
|
# write new profile to database
|
||||||
|
import sys
|
||||||
|
sys.path.append(msettings.MADIS_PATH)
|
||||||
|
import madis
|
||||||
|
# database file name
|
||||||
|
database_file_name = "users_files/OAMiningProfilesDatabase_{0}.db".format(user_id)
|
||||||
|
# get the database cursor
|
||||||
|
cursor=madis.functions.Connection(database_file_name).cursor()
|
||||||
|
user_profiles = []
|
||||||
|
cursor.execute('''UPDATE database SET notified=1 WHERE id=?''', (profile_id,), parse=False)
|
||||||
|
cursor.close()
|
||||||
|
|
||||||
|
self.write(json.dumps({}))
|
||||||
|
self.finish()
|
||||||
|
except Exception as ints:
|
||||||
|
self.set_status(400)
|
||||||
|
self.write("A server error occurred, please contact administrator!")
|
||||||
|
self.finish()
|
||||||
|
print ints
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
def getqtext(query,params):
|
def getqtext(query,params):
|
||||||
query=query.strip('\n \s')
|
query=query.strip('\n \s')
|
||||||
|
|
|
@ -11,6 +11,14 @@ MADIS_PATH='../../../interactive-mining-3rdparty-madis/madis/src'
|
||||||
DB='static/database.db'
|
DB='static/database.db'
|
||||||
RESET_FIELDS=1
|
RESET_FIELDS=1
|
||||||
|
|
||||||
|
# SMTP_EMAIL SETTINGS
|
||||||
|
SMTP_HOST = 'smtp.gmail.com'
|
||||||
|
SMTP_PORT = 587
|
||||||
|
SMTP_AUTH = True
|
||||||
|
SMTP_FROM = 'openaire.test@gmail.com'
|
||||||
|
SMTP_USERNAME = 'openaire.test@gmail.com'
|
||||||
|
SMTP_PASSWORD = '...'
|
||||||
|
|
||||||
FLOW_PATH=''
|
FLOW_PATH=''
|
||||||
|
|
||||||
# Change this. Make this unique, and don't share it with anybody.
|
# Change this. Make this unique, and don't share it with anybody.
|
||||||
|
|
Loading…
Reference in New Issue