Skip to content

Commit

Permalink
feat: Enhance Search Page
Browse files Browse the repository at this point in the history
Signed-off-by: Jerrico Dela Cruz <[email protected]>
  • Loading branch information
jerricotandelacruz committed Oct 16, 2024
1 parent b681aea commit 6a2ff69
Show file tree
Hide file tree
Showing 8 changed files with 454 additions and 412 deletions.
14 changes: 9 additions & 5 deletions src/goapp/pkg/ghmgmtdb/ghmgmtDb.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,27 @@ func ConnectDb() *sql.DB {
return db
}

func SearchCommunitiesProjectsUsers(searchText, offSet, rowCount, username string) ([]map[string]interface{}, error) {
func SearchCommunitiesProjectsUsers(searchText, offSet, filter, selectedSourceType, username string) ([]map[string]interface{}, int, error) {
db := ConnectDb()
defer db.Close()

params := map[string]interface{}{
"Search": searchText,
"OffSet": offSet,
"RowCount": rowCount,
"Filter": filter,
"UserPrincipalName": username,
}

result, err := db.ExecuteStoredProcedureWithResult("usp_Search", params)
if selectedSourceType != "" {
params["SelectedSourceType"] = selectedSourceType
}

result, total, err := db.ExecuteStoredProcedureWithResultTotal("usp_Search", params)
if err != nil {
return nil, err
return nil, 0, err
}

return result, err
return result, total, err
}

func UpdateProjectApprovalApproverResponse(itemId, remarks, responseDate, respondedBy string, approvalStatusId int) (bool, error) {
Expand Down
56 changes: 56 additions & 0 deletions src/goapp/pkg/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,59 @@ func (db *DB) ExecuteStoredProcedureWithResult(procedure string, params map[stri

return results, nil
}

func (db *DB) ExecuteStoredProcedureWithResultTotal(procedure string, params map[string]interface{}) ([]map[string]interface{}, int, error) {
var args []interface{}

ctx := context.Background()

for i, v := range params {
args = append(args, sql.Named(i, v))
}

rows, err := db.QueryContext(ctx, procedure, args...)
if err != nil {
return nil, 0, err
}

defer rows.Close()

columns, err := rows.Columns()
if err != nil {
return nil, 0, err
}

var results []map[string]interface{}

for rows.Next() {
values := make([]interface{}, len(columns))
pointers := make([]interface{}, len(columns))
for i, _ := range values {
pointers[i] = &values[i]
}
err := rows.Scan(pointers...)
if err != nil {
return nil, 0, err
}
result := make(map[string]interface{})
for i, val := range values {
result[columns[i]] = val
}
results = append(results, result)
}

var totalCount int

// Fetch the total count
if rows.NextResultSet() {
if rows.Next() {
err := rows.Scan(&totalCount)
if err != nil {
log.Fatal("Error scanning total count: ", err.Error())
}
fmt.Printf("Total Count: %d\n", totalCount)
}
}

return results, totalCount, nil
}
2 changes: 1 addition & 1 deletion src/goapp/public/components/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ const table = ({
this.load()
},
onSearchSubmit(e){
this.filter = 10;
this.page = 0;
this.search = e.target.value;
this.load();
Expand Down Expand Up @@ -214,6 +213,7 @@ const table = ({
x-bind:colspan='columns.length'>
<p class="text-center my-5">NO RESULT FOUND</p>
</td>
</tr>
<tr x-show='isLoading' x-transition>
<td x-bind:colspan='columns.length'>
<svg
Expand Down
50 changes: 15 additions & 35 deletions src/goapp/public/css/output.css
Original file line number Diff line number Diff line change
Expand Up @@ -2015,10 +2015,6 @@ select {
margin-left: -0.25rem;
}

.-ml-px {
margin-left: -1px;
}

.-mr-0 {
margin-right: -0px;
}
Expand All @@ -2027,10 +2023,6 @@ select {
margin-right: -0.125rem;
}

.-mr-1 {
margin-right: -0.25rem;
}

.-mr-12 {
margin-right: -3rem;
}
Expand Down Expand Up @@ -3413,10 +3405,6 @@ select {
border-radius: 0.375rem;
}

.rounded-none {
border-radius: 0px;
}

.rounded-xl {
border-radius: 0.75rem;
}
Expand All @@ -3431,11 +3419,6 @@ select {
border-bottom-left-radius: 0.25rem;
}

.rounded-l-md {
border-top-left-radius: 0.375rem;
border-bottom-left-radius: 0.375rem;
}

.rounded-r {
border-top-right-radius: 0.25rem;
border-bottom-right-radius: 0.25rem;
Expand Down Expand Up @@ -5627,6 +5610,11 @@ select {
background-color: rgb(254 202 202 / var(--tw-bg-opacity));
}

.hover\:bg-sky-200:hover {
--tw-bg-opacity: 1;
background-color: rgb(186 230 253 / var(--tw-bg-opacity));
}

.hover\:font-bold:hover {
font-weight: 700;
}
Expand All @@ -5646,6 +5634,11 @@ select {
color: rgb(55 65 81 / var(--tw-text-opacity));
}

.hover\:text-gray-800:hover {
--tw-text-opacity: 1;
color: rgb(31 41 55 / var(--tw-text-opacity));
}

.hover\:text-gray-900:hover {
--tw-text-opacity: 1;
color: rgb(17 24 39 / var(--tw-text-opacity));
Expand Down Expand Up @@ -5676,6 +5669,11 @@ select {
color: rgb(202 138 4 / var(--tw-text-opacity));
}

.hover\:text-orange-500:hover {
--tw-text-opacity: 1;
color: rgb(249 115 22 / var(--tw-text-opacity));
}

.hover\:underline:hover {
text-decoration-line: underline;
}
Expand Down Expand Up @@ -5735,11 +5733,6 @@ select {
border-color: rgb(249 115 22 / var(--tw-border-opacity));
}

.focus\:border-red-500:focus {
--tw-border-opacity: 1;
border-color: rgb(239 68 68 / var(--tw-border-opacity));
}

.focus\:border-rose-500:focus {
--tw-border-opacity: 1;
border-color: rgb(244 63 94 / var(--tw-border-opacity));
Expand Down Expand Up @@ -5852,11 +5845,6 @@ select {
--tw-ring-color: rgb(249 115 22 / var(--tw-ring-opacity));
}

.focus\:ring-red-500:focus {
--tw-ring-opacity: 1;
--tw-ring-color: rgb(239 68 68 / var(--tw-ring-opacity));
}

.focus\:ring-rose-500:focus {
--tw-ring-opacity: 1;
--tw-ring-color: rgb(244 63 94 / var(--tw-ring-opacity));
Expand All @@ -5879,10 +5867,6 @@ select {
--tw-ring-offset-width: 2px;
}

.focus\:ring-offset-gray-100:focus {
--tw-ring-offset-color: #f3f4f6;
}

.focus\:hover\:text-center:hover:focus {
text-align: center;
}
Expand Down Expand Up @@ -6466,10 +6450,6 @@ select {
justify-content: space-between;
}

.md\:rounded-lg {
border-radius: 0.5rem;
}

.md\:px-6 {
padding-left: 1.5rem;
padding-right: 1.5rem;
Expand Down
4 changes: 3 additions & 1 deletion src/goapp/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func setPageRoutes() {
httpRouter.GET("/Home/AssetRequestCreation", rtApi.RedirectAssetRequest)
httpRouter.GET("/Home/AssetRequestCreation/", rtApi.RedirectAssetRequest)
httpRouter.GET("/Home/Tool/{assetCode}", m.Chain(rtPages.ToolHandler, m.AzureAuth()))
httpRouter.GET("/search/{offSet}/{rowCount}", m.Chain(rtSearch.GetSearchResults, m.AzureAuth(), m.GitHubAuth()))
}

func setAdminPageRoutes() {
Expand Down Expand Up @@ -253,6 +252,9 @@ func setApiRoutes() {

// LEGACY APIS
httpRouter.GET("/api/searchresult/{searchText}", m.Chain(rtApi.LegacySearchHandler, m.GuidAuth()))

// SEARCH API
httpRouter.GET("/api/search", m.Chain(rtSearch.GetSearchResults, m.AzureAuth(), m.GitHubAuth()))
}

func setUtilityRoutes() {
Expand Down
22 changes: 14 additions & 8 deletions src/goapp/routes/pages/search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
db "main/pkg/ghmgmtdb"
"main/pkg/session"
"main/pkg/template"

"github.com/gorilla/mux"
)

func SearchHandler(w http.ResponseWriter, r *http.Request) {
Expand All @@ -18,17 +16,19 @@ func SearchHandler(w http.ResponseWriter, r *http.Request) {
}

func GetSearchResults(w http.ResponseWriter, r *http.Request) {
req := mux.Vars(r)
params := r.URL.Query()

search := params.Get("search")
offset := params.Get("offset")
filter := params.Get("filter")
selectedSourceType := params.Get("selectedSourceType")

searchText := r.URL.Query().Get("search")
offSet := req["offSet"]
rowCount := req["rowCount"]
sessionaz, _ := session.Store.Get(r, "auth-session")
iprofile := sessionaz.Values["profile"]
profile := iprofile.(map[string]interface{})
username := profile["preferred_username"].(string)

searchResults, err := db.SearchCommunitiesProjectsUsers(searchText, offSet, rowCount, username)
data, total, err := db.SearchCommunitiesProjectsUsers(search, offset, filter, selectedSourceType, username)
if err != nil {
log.Println(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand All @@ -37,7 +37,13 @@ func GetSearchResults(w http.ResponseWriter, r *http.Request) {

w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
jsonResp, err := json.Marshal(searchResults)
jsonResp, err := json.Marshal(struct {
Data []map[string]interface{} `json:"data"`
Total int `json:"total"`
}{
Data: data,
Total: total,
})
if err != nil {
log.Println(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down
Loading

0 comments on commit 6a2ff69

Please sign in to comment.