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-expand cm-text-muted">Profile</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-table-shrink uk-text-nowrap">Matches</th>-->
|
||||
<th></th>
|
||||
|
@ -96,6 +97,11 @@
|
|||
<a class="uk-link-reset" (click)="loadSavedProfile(profile.id, profile.name)">{{profile.name}}</a>
|
||||
</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">{{profile.matches}}</td>-->
|
||||
<td class="delete">
|
||||
|
|
|
@ -19,10 +19,12 @@ export class ManageprofilesComponent implements OnInit {
|
|||
|
||||
public allUsersProfiles: Array<UsersMetadata> = [];
|
||||
public statusValues = [
|
||||
'Saved',
|
||||
'Processing',
|
||||
'Evaluating',
|
||||
'On Beta'
|
||||
];
|
||||
|
||||
public communityId = '';
|
||||
public isCommunityManager = false;
|
||||
|
||||
public userSavedProfiles: Array<ProfileMetadata> = [];
|
||||
|
@ -34,6 +36,8 @@ export class ManageprofilesComponent implements OnInit {
|
|||
currentPage: 1
|
||||
};
|
||||
|
||||
public pending = false;
|
||||
|
||||
constructor(private manageProfilesService: ManageprofilesService, private route: ActivatedRoute, private router: Router) {
|
||||
}
|
||||
|
||||
|
@ -41,8 +45,9 @@ export class ManageprofilesComponent implements OnInit {
|
|||
this.route.queryParams
|
||||
.subscribe(
|
||||
params => {
|
||||
console.log('queryParams', params['communityId']);
|
||||
this.initialServerhandshake(params['communityId']);
|
||||
// console.log('queryParams', params['communityId']);
|
||||
this.communityId = params['communityId'];
|
||||
this.initialServerhandshake(this.communityId);
|
||||
});
|
||||
this.isCommunityManager = this.manageProfilesService.isCommunityManager === 'true';
|
||||
}
|
||||
|
@ -193,6 +198,18 @@ export class ManageprofilesComponent implements OnInit {
|
|||
.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 {
|
||||
// clear localstorage values
|
||||
this.clearLocalStorage();
|
||||
|
|
|
@ -27,6 +27,7 @@ export class ManageprofilesService {
|
|||
private getExampleProfilesUrl = '/getexampleprofiles';
|
||||
private loadExampleProfileUrl = '/loadexampleprofile';
|
||||
private uploadProfileUrl = '/uploadprofile';
|
||||
private notifyProfileUrl = '/notifyforprofile';
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
this.userId = this.util.getUserId();
|
||||
|
@ -114,4 +115,9 @@ export class ManageprofilesService {
|
|||
.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;
|
||||
status: string;
|
||||
matches: string;
|
||||
notified: number;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,8 @@ class Application(tornado.web.Application):
|
|||
(r"/runmining", RunMiningHandler),
|
||||
(r"/preparesavedprofile", PrepareSavedProfileHandler),
|
||||
(r"/saveprofile", SaveProfileToDatabaseHandler),
|
||||
(r"/downloadprofile", DownloadProfileHandler)
|
||||
(r"/downloadprofile", DownloadProfileHandler),
|
||||
(r"/notifyforprofile", NotifyHandler)
|
||||
]
|
||||
|
||||
|
||||
|
@ -467,8 +468,8 @@ class GetUsersProfilesHandler(BaseHandler):
|
|||
except Exception as ints:
|
||||
print ints
|
||||
community_id = 'Unkown '+user
|
||||
for r in cursor.execute('''SELECT id,name,datecreated,status,matches,docname 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]})
|
||||
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], "notified": r[6] })
|
||||
data['profiles'] = users_profiles
|
||||
self.write(json.dumps(data))
|
||||
self.finish()
|
||||
|
@ -513,7 +514,7 @@ class UpdateProfileStatusHandler(BaseHandler):
|
|||
cursor=madis.functions.Connection(database_file_name).cursor()
|
||||
# Write new Profile status to users database
|
||||
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()
|
||||
self.write(json.dumps({}))
|
||||
self.finish()
|
||||
|
@ -560,8 +561,8 @@ class GetUserProfilesHandler(BaseHandler):
|
|||
# data to be sent
|
||||
data = {}
|
||||
user_profiles = []
|
||||
for r in cursor.execute('''SELECT id,name,datecreated,status,matches,docname 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]})
|
||||
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], "notified": r[6]})
|
||||
data['profiles'] = user_profiles
|
||||
cursor.close()
|
||||
self.write(json.dumps(data))
|
||||
|
@ -1603,9 +1604,9 @@ class SaveProfileToDatabaseHandler(BaseHandler):
|
|||
cursor=madis.functions.Connection(database_file_name).cursor()
|
||||
user_profiles = []
|
||||
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:
|
||||
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()
|
||||
self.write(json.dumps({}))
|
||||
self.finish()
|
||||
|
@ -1659,6 +1660,66 @@ class DownloadProfileHandler(BaseHandler):
|
|||
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 getqtext(query,params):
|
||||
query=query.strip('\n \s')
|
||||
|
|
|
@ -11,6 +11,14 @@ MADIS_PATH='../../../interactive-mining-3rdparty-madis/madis/src'
|
|||
DB='static/database.db'
|
||||
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=''
|
||||
|
||||
# Change this. Make this unique, and don't share it with anybody.
|
||||
|
|
Loading…
Reference in New Issue