Show skills on profile screen

master
Bob Mottram 2019-07-22 21:01:46 +01:00
parent 1e5b44aef1
commit 84de304df0
3 changed files with 155 additions and 87 deletions

View File

@ -567,7 +567,7 @@ class PubServer(BaseHTTPRequestHandler):
getPerson = \ getPerson = \
personLookup(self.server.domain,self.path.replace('/roles',''), \ personLookup(self.server.domain,self.path.replace('/roles',''), \
self.server.baseDir) self.server.baseDir)
if getPerson: if getPerson:
self._set_headers('text/html') self._set_headers('text/html')
self.wfile.write(htmlProfile(self.server.baseDir, \ self.wfile.write(htmlProfile(self.server.baseDir, \
self.server.httpPrefix, \ self.server.httpPrefix, \
@ -581,9 +581,40 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
self._set_headers('application/json') self._set_headers('application/json')
self.wfile.write(json.dumps(actorJson['roles']).encode('utf-8')) self.wfile.write(json.dumps(actorJson['roles']).encode('utf-8'))
self.server.GETbusy=False self.server.GETbusy=False
return return
if self.path.endswith('/skills') and '/users/' in self.path:
namedStatus=self.path.split('/users/')[1]
if '/' in namedStatus:
postSections=namedStatus.split('/')
nickname=postSections[0]
actorFilename=self.server.baseDir+'/accounts/'+nickname+'@'+self.server.domain+'.json'
if os.path.isfile(actorFilename):
with open(actorFilename, 'r') as fp:
actorJson=commentjson.load(fp)
if actorJson.get('skills'):
if 'text/html' in self.headers['Accept']:
getPerson = \
personLookup(self.server.domain,self.path.replace('/skills',''), \
self.server.baseDir)
if getPerson:
self._set_headers('text/html')
self.wfile.write(htmlProfile(self.server.baseDir, \
self.server.httpPrefix, \
True, \
self.server.ocapAlways, \
getPerson,'skills', \
self.server.session, \
self.server.cachedWebfingers, \
self.server.personCache, \
actorJson['skills']).encode('utf-8'))
else:
self._set_headers('application/json')
self.wfile.write(json.dumps(actorJson['skills']).encode('utf-8'))
self.server.GETbusy=False
return
# get an individual post from the path /users/nickname/statuses/number # get an individual post from the path /users/nickname/statuses/number
if '/statuses/' in self.path and '/users/' in self.path: if '/statuses/' in self.path and '/users/' in self.path:
namedStatus=self.path.split('/users/')[1] namedStatus=self.path.split('/users/')[1]

View File

@ -1,139 +1,139 @@
body, html { body, html {
height: 100%; height: 100%;
margin: 0; margin: 0;
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
} }
.hero-image { .hero-image {
background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url("image.png"); background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url("image.png");
height: 50%; height: 50%;
background-position: center; background-position: center;
background-repeat: no-repeat; background-repeat: no-repeat;
background-size: cover; background-size: cover;
position: relative; position: relative;
} }
.hero-text { .hero-text {
text-align: center; text-align: center;
position: absolute; position: absolute;
top: 50%; top: 50%;
left: 50%; left: 50%;
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
color: white; color: white;
} }
.roles { .roles {
text-align: center; text-align: center;
left: 35%; left: 35%;
background-color: #f1f1f1; background-color: #f1f1f1;
} }
.roles-inner { .roles-inner {
padding: 10px 25px; padding: 10px 25px;
background-color: #ffffff; background-color: #ffffff;
} }
.hero-text img { .hero-text img {
border-radius: 10%; border-radius: 10%;
width: 50%; width: 50%;
} }
.hero-text button { .hero-text button {
border: none; border: none;
outline: 0; outline: 0;
display: inline-block; display: inline-block;
padding: 10px 25px; padding: 10px 25px;
color: black; color: black;
background-color: #ddd; background-color: #ddd;
text-align: center; text-align: center;
cursor: pointer; cursor: pointer;
} }
.hero-text button:hover { .hero-text button:hover {
background-color: #555; background-color: #555;
color: white; color: white;
} }
.button { .button {
border-radius: 4px; border-radius: 4px;
background-color: #999; background-color: #999;
border: none; border: none;
color: #FFFFFF; color: #FFFFFF;
text-align: center; text-align: center;
font-size: 18px; font-size: 18px;
padding: 10px; padding: 10px;
width: 20%; width: 20%;
max-width: 200px; max-width: 200px;
min-width: 100px; min-width: 100px;
transition: all 0.5s; transition: all 0.5s;
cursor: pointer; cursor: pointer;
margin: 5px; margin: 5px;
} }
.button span { .button span {
cursor: pointer; cursor: pointer;
display: inline-block; display: inline-block;
position: relative; position: relative;
transition: 0.5s; transition: 0.5s;
} }
.button span:after { .button span:after {
content: '\00bb'; content: '\00bb';
position: absolute; position: absolute;
opacity: 0; opacity: 0;
top: 0; top: 0;
right: -20px; right: -20px;
transition: 0.5s; transition: 0.5s;
} }
.button:hover span { .button:hover span {
padding-right: 25px; padding-right: 25px;
} }
.button:hover span:after { .button:hover span:after {
opacity: 1; opacity: 1;
right: 0; right: 0;
} }
.buttonselected { .buttonselected {
border-radius: 4px; border-radius: 4px;
background-color: #666; background-color: #666;
border: none; border: none;
color: #FFFFFF; color: #FFFFFF;
text-align: center; text-align: center;
font-size: 18px; font-size: 18px;
padding: 10px; padding: 10px;
width: 20%; width: 20%;
max-width: 200px; max-width: 200px;
min-width: 100px; min-width: 100px;
transition: all 0.5s; transition: all 0.5s;
cursor: pointer; cursor: pointer;
margin: 5px; margin: 5px;
} }
.buttonselected span { .buttonselected span {
cursor: pointer; cursor: pointer;
display: inline-block; display: inline-block;
position: relative; position: relative;
transition: 0.5s; transition: 0.5s;
} }
.buttonselected span:after { .buttonselected span:after {
content: '\00bb'; content: '\00bb';
position: absolute; position: absolute;
opacity: 0; opacity: 0;
top: 0; top: 0;
right: -20px; right: -20px;
transition: 0.5s; transition: 0.5s;
} }
.buttonselected:hover span { .buttonselected:hover span {
padding-right: 25px; padding-right: 25px;
} }
.buttonselected:hover span:after { .buttonselected:hover span:after {
opacity: 1; opacity: 1;
right: 0; right: 0;
} }
.container { .container {
@ -197,3 +197,25 @@ body, html {
margin-top: 0px; margin-top: 0px;
color: #999; color: #999;
} }
.skill-title {
margin-left: 25%;
text-align: left;
font-size: 24px;
font-weight: bold;
color: #666;
line-height: 40px;
}
#myProgress {
float: left;
width: 70%;
background-color: #f1f1f1;
}
#myBar {
float: left;
width: 10%;
height: 30px;
background-color: #999;
}

View File

@ -86,6 +86,18 @@ def htmlProfileRoles(nickname: str,domain: str,rolesJson: {}) -> str:
profileStr='<div>'+profileStr+'</div>' profileStr='<div>'+profileStr+'</div>'
return profileStr return profileStr
def htmlProfileSkills(nickname: str,domain: str,skillsJson: {}) -> str:
"""Shows skills on the profile screen
"""
profileStr=''
for skill,level in skillsJson.items():
profileStr+='<div>'+skill+'<br><div id="myProgress"><div id="myBar" style="width:'+str(level)+'%"></div></div></div><br>'
if len(profileStr)==0:
profileStr+='<p>@'+nickname+'@'+domain+' has no skills assigned</p>'
else:
profileStr='<center><div class="skill-title">'+profileStr+'</div></center>'
return profileStr
def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool, \ def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool, \
ocapAlways: bool,profileJson: {},selected: str, \ ocapAlways: bool,profileJson: {},selected: str, \
session,wfRequest: {},personCache: {}, \ session,wfRequest: {},personCache: {}, \
@ -160,6 +172,9 @@ def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool, \
if selected=='roles': if selected=='roles':
profileStr+= \ profileStr+= \
htmlProfileRoles(nickname,domainFull,extraJson) htmlProfileRoles(nickname,domainFull,extraJson)
if selected=='skills':
profileStr+= \
htmlProfileSkills(nickname,domainFull,extraJson)
profileStr=htmlHeader(profileStyle)+profileStr+htmlFooter() profileStr=htmlHeader(profileStyle)+profileStr+htmlFooter()
return profileStr return profileStr