Skip to content

Commit

Permalink
Added user statistics (#2431)
Browse files Browse the repository at this point in the history
* Added user statistics
  • Loading branch information
Cheshiriks authored Aug 8, 2023
1 parent fb11344 commit 64f1b21
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class OrganizationService(
@Suppress("UnsafeCallOnNullableType", "TooGenericExceptionCaught")
@Transactional
fun saveOrganization(organization: Organization): Pair<Long, OrganizationSaveStatus> {
val (organizationId, organizationSaveStatus) = if (organization.name.isValidLengthName()) {
val (organizationId, organizationSaveStatus) = if (!organization.name.isValidLengthName()) {
Pair(0L, OrganizationSaveStatus.INVALID_NAME)
} else if (organizationRepository.validateName(organization.name) != 0L) {
organizationRepository.saveHighLevelName(organization.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ import kotlinx.datetime.TimeZone
import kotlinx.datetime.toInstant
import kotlinx.datetime.toLocalDateTime

// FixMe: Current Rating in Vulnerabilities
// FixMe: Latest notifications - for example: your Vuln was accepted or Change requested
// FixMe: Some statistics: may be how many users used your demo or how many contests you created,
// FixMe: How many vuln were submitted and accepted, ranking in TOP ratings: for contests and more
// FixMe: Statistics about demo

private const val REGISTER_NOW = """
Expand All @@ -55,24 +53,27 @@ val cardUser: FC<IndexViewProps> = FC { props ->
val (countVulnerability, setCountVulnerability) = useState(0)
val navigate = useNavigate()

@Suppress("TOO_MANY_LINES_IN_LAMBDA")
useRequest {
val organizationsNew: List<OrganizationDto> = get(
"$apiUrl/organizations/get/list-by-user-name?userName=${props.userInfo?.name}",
jsonHeaders,
loadingHandler = ::loadingHandler,
)
.decodeFromJsonString()

setOrganizations(organizationsNew)

val countVuln: Int = get(
"$apiUrl/vulnerabilities/count-by-user?userName=${props.userInfo?.name}",
jsonHeaders,
loadingHandler = ::loadingHandler,
)
.decodeFromJsonString()

setCountVulnerability(countVuln)
props.userInfo?.name?.let {
val organizationsNew: List<OrganizationDto> = get(
"$apiUrl/organizations/get/list-by-user-name?userName=$it",
jsonHeaders,
loadingHandler = ::loadingHandler,
)
.decodeFromJsonString()

setOrganizations(organizationsNew)

val countVuln: Int = get(
"$apiUrl/vulnerabilities/count-by-user?userName=$it",
jsonHeaders,
loadingHandler = ::loadingHandler,
)
.decodeFromJsonString()

setCountVulnerability(countVuln)
}
}

div {
Expand Down Expand Up @@ -168,48 +169,102 @@ val cardUser: FC<IndexViewProps> = FC { props ->
}
}

div {
className = ClassName("mt-2")
props.userInfo?.let {
div {
className = ClassName("row d-flex justify-content-center text-gray-900 mt-2")
h5 {
style = jso {
textAlign = TextAlign.center
}
+"Your organizations:"
}
}
if (organizations.isEmpty()) {
className = ClassName("mt-2")
div {
className = ClassName("row d-flex justify-content-center mt-1")
buttonBuilder(
"Create",
style = "primary rounded-pill",
isOutline = false
) {
navigate(to = "/${FrontendRoutes.CREATE_ORGANIZATION}")
className = ClassName("row d-flex justify-content-center text-gray-900 mt-2")
h5 {
style = jso {
textAlign = TextAlign.center
}
+"Your organizations:"
}
}
} else {
organizations.forEach { organization ->
if (organizations.isEmpty()) {
div {
className = ClassName("row d-flex justify-content-center")
className = ClassName("row d-flex justify-content-center mt-1")
buttonBuilder(
"Create",
style = "primary rounded-pill",
isOutline = false
) {
navigate(to = "/${FrontendRoutes.CREATE_ORGANIZATION}")
}
}
} else {
organizations.forEach { organization ->
div {
className = ClassName("col-12 mt-2")
val renderImg: ChildrenBuilder.() -> Unit = {
renderAvatar(organization) {
height = 2.rem
width = 2.rem
className = ClassName("row d-flex justify-content-center")
div {
className = ClassName("col-12 mt-2")
val renderImg: ChildrenBuilder.() -> Unit = {
renderAvatar(organization) {
height = 2.rem
width = 2.rem
}
+" ${organization.name}"
}
+" ${organization.name}"
}
if (organization.status != OrganizationStatus.DELETED) {
Link {
to = "/${organization.name}"
if (organization.status != OrganizationStatus.DELETED) {
Link {
to = "/${organization.name}"
renderImg()
}
} else {
renderImg()
}
} else {
renderImg()
}
}
}
}
}

div {
className = ClassName("mt-2")
div {
className = ClassName("row d-flex justify-content-center text-gray-900 mt-2")
h5 {
style = jso {
textAlign = TextAlign.center
}
+"Your statistics:"
}
}
div {
className = ClassName("row text-muted border-bottom border-gray mx-3")
div {
className = ClassName("col-9")
p {
+"Vulnerabilities: "
}
}

div {
className = ClassName("col-3")
p {
Link {
to = "/${FrontendRoutes.PROFILE}/${props.userInfo?.name}"
+countVulnerability.toString()
}
}
}
}

div {
className = ClassName("row text-muted border-bottom border-gray mx-3")
div {
className = ClassName("col-9")
p {
+"Top rating: "
}
}

div {
className = ClassName("col-3")
p {
Link {
to = "/${FrontendRoutes.VULN_TOP_RATING}"
+"${props.userInfo?.rating ?: 0}"
}
}
}
Expand Down

0 comments on commit 64f1b21

Please sign in to comment.