diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/ManualQueryOverview.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/ManualQueryOverview.java deleted file mode 100644 index de80ffa..0000000 --- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/ManualQueryOverview.java +++ /dev/null @@ -1,4 +0,0 @@ -package gearth.services.internal_extensions.extensionstore.application.entities.queriedoverviews; - -public class ManualQueryOverview { -} diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/SearchedQueryOverview.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/SearchedQueryOverview.java new file mode 100644 index 0000000..0709ced --- /dev/null +++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/queriedoverviews/SearchedQueryOverview.java @@ -0,0 +1,72 @@ +package gearth.services.internal_extensions.extensionstore.application.entities.queriedoverviews; + +import gearth.misc.OSValidator; +import gearth.services.internal_extensions.extensionstore.application.entities.HOverview; +import gearth.services.internal_extensions.extensionstore.repository.StoreRepository; +import gearth.services.internal_extensions.extensionstore.repository.models.StoreExtension; +import gearth.services.internal_extensions.extensionstore.repository.querying.ExtensionOrdering; + +import java.util.Collections; +import java.util.List; + +public class SearchedQueryOverview extends QueriedExtensionOverview { + + private final String queryString; + private final ExtensionOrdering ordering; + private final List filterClients; + private final List filterFrameworks; + private final List filterCategories; + private final boolean includeOutdated; + private final boolean invert; + + public SearchedQueryOverview(HOverview parent, int startIndex, int size, StoreRepository storeRepository, String queryString, ExtensionOrdering ordering, List filterClients, List filterFrameworks, List filterCategories, boolean includeOutdated, boolean invert) { + super(parent, startIndex, size, storeRepository); + this.queryString = queryString; + this.ordering = ordering; + this.filterClients = filterClients; + this.filterFrameworks = filterFrameworks; + this.filterCategories = filterCategories; + this.includeOutdated = includeOutdated; + this.invert = invert; + } + + @Override + protected List query(int startIndex, int size) { + return storeRepository.getExtensions(startIndex, size, queryString, ordering, + Collections.singletonList(OSValidator.getOSFull()), filterClients, filterFrameworks, + filterCategories, includeOutdated, invert); + + } + + @Override + public Header header() { + return new Header() { + @Override + public String iconUrl() { + return "images/overviews/search.png"; + } + + @Override + public String title() { + return "Search"; + } + + @Override + public String description() { + return "Find the extension that fits your needs"; + } + + @Override + public String contentTitle() { + return "Search results"; + } + }; + } + + @Override + public HOverview getNewPage(int startIndex, int size) { + return new SearchedQueryOverview(parent, startIndex, size, storeRepository, + queryString, ordering, filterClients, filterFrameworks, filterCategories, + includeOutdated, invert); + } +} diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/search/SearchComponent.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/search/SearchComponent.java index df64070..b53b3f1 100644 --- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/search/SearchComponent.java +++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/search/SearchComponent.java @@ -1,12 +1,168 @@ package gearth.services.internal_extensions.extensionstore.application.entities.search; import gearth.services.internal_extensions.extensionstore.GExtensionStore; +import gearth.services.internal_extensions.extensionstore.application.GExtensionStoreController; import gearth.services.internal_extensions.extensionstore.application.entities.ContentItem; +import gearth.services.internal_extensions.extensionstore.repository.StoreRepository; +import gearth.services.internal_extensions.extensionstore.repository.querying.ExtensionOrdering; +import netscape.javascript.JSObject; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; public class SearchComponent implements ContentItem { + private StoreRepository repository; + + private volatile String searchKeyword; + private volatile ExtensionOrdering ordering; + + private volatile Map clients; + private volatile Map categories; + private volatile Map frameworks; + + public SearchComponent(StoreRepository repository) { + this.repository = repository; + + this.searchKeyword = ""; + this.ordering = ExtensionOrdering.ALPHABETICAL; + this.clients = new HashMap<>(); + this.categories = new HashMap<>(); + this.frameworks = new HashMap<>(); + + repository.getClients().forEach(c -> clients.put(c, true)); + repository.getCategories().forEach(c -> categories.put(c.getName(), true)); + repository.getFrameworks().forEach(c -> frameworks.put(c.getName(), true)); + } + + public void setOrdering(String ordering) { + this.ordering = ExtensionOrdering.fromString(ordering); + } + + public void setSearchKeyword(String searchKeyword) { + this.searchKeyword = searchKeyword; + } + + public void setClient(String client, boolean enabled) { + clients.put(client, enabled); + } + + public void setCategory(String category, boolean enabled) { + categories.put(category, enabled); + } + + public void setFramework(String framework, boolean enabled) { + frameworks.put(framework, enabled); + } + + private void addFilterBoxHtml(StringBuilder htmlBuilder, String name, String title, Map data, String id) { + htmlBuilder.append("
"); + + htmlBuilder.append(String.format("

%s

", title)); + List items = new ArrayList<>(data.keySet()); + for (int i = 0; i < items.size(); i++) { + String item = items.get(i); + String checkboxId = name.toLowerCase() + i; + htmlBuilder.append(String.format("", + checkboxId, + data.get(item) ? " checked" : "", + id, + name, + item + )); + htmlBuilder.append(String.format("
", checkboxId, item)); + } + + htmlBuilder.append("
"); + } + + @Override public void addHtml(int i, GExtensionStore gExtensionStore) { + String id = "search" + i + "_" + System.currentTimeMillis(); + + StringBuilder htmlBuilder = new StringBuilder(); + + htmlBuilder + .append("
") + .append("
") + + .append("
") + .append("") + .append(String.format("", searchKeyword, id)) + .append("
") + + .append("
") + .append(""); + + // add ordering stuff + htmlBuilder.append(String.format("") + .append("
") + + .append("
"); + + addFilterBoxHtml(htmlBuilder, "Client", "Clients:", clients, id); + addFilterBoxHtml(htmlBuilder, "Category", "Categories:", categories, id); + addFilterBoxHtml(htmlBuilder, "Framework", "Frameworks:", frameworks, id); + + htmlBuilder + .append("
") + .append("

Info: you are automatically filtering on the OS you use

") + + .append("
") + .append("
"); + + + String searchHtml = htmlBuilder.toString(); + GExtensionStoreController controller = gExtensionStore.getController(); + + controller.getWebView().getEngine().executeScript("document.getElementById('" + controller.getContentItemsContainer() + "').innerHTML += '" + searchHtml + "';"); + + JSObject window = (JSObject) controller.getWebView().getEngine().executeScript("window"); + window.setMember(id, this); + + } + + + public StoreRepository getRepository() { + return repository; + } + + public List getCategories() { + return categories.keySet().stream().filter(c -> categories.get(c)).collect(Collectors.toList()); + } + + public List getClients() { + return clients.keySet().stream().filter(c -> clients.get(c)).collect(Collectors.toList()); + } + + public List getFrameworks() { + return frameworks.keySet().stream().filter(f -> frameworks.get(f)).collect(Collectors.toList()); + } + + public ExtensionOrdering getOrdering() { + return ordering; + } + + public String getSearchKeyword() { + return searchKeyword; } } diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/search/SearchOverview.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/search/SearchOverview.java index 7666bbb..1c23d4d 100644 --- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/search/SearchOverview.java +++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/application/entities/search/SearchOverview.java @@ -3,6 +3,8 @@ package gearth.services.internal_extensions.extensionstore.application.entities. import gearth.services.internal_extensions.extensionstore.GExtensionStore; import gearth.services.internal_extensions.extensionstore.application.entities.ContentItem; import gearth.services.internal_extensions.extensionstore.application.entities.HOverview; +import gearth.services.internal_extensions.extensionstore.application.entities.extensiondetails.StoreExtensionDetailsOverview; +import gearth.services.internal_extensions.extensionstore.application.entities.queriedoverviews.SearchedQueryOverview; import gearth.services.internal_extensions.extensionstore.repository.StoreRepository; import java.util.Collections; @@ -10,27 +12,32 @@ import java.util.List; public class SearchOverview extends HOverview { + private static SearchComponent searchComponent = null; private final StoreRepository storeRepository; public SearchOverview(HOverview parent, StoreRepository storeRepository) { super(null, 0, 1); this.storeRepository = storeRepository; + + if (searchComponent == null || searchComponent.getRepository() != storeRepository) { + searchComponent = new SearchComponent(storeRepository); + } } @Override public String buttonText() { - return null; + return "Search"; } @Override public boolean buttonEnabled() { - return false; + return true; } @Override public List getContentItems() { - return Collections.singletonList(new SearchComponent()); + return Collections.singletonList(searchComponent); } @Override @@ -40,7 +47,21 @@ public class SearchOverview extends HOverview { @Override public void buttonClick(GExtensionStore gExtensionStore) { - // nothing + gExtensionStore.getController().pushOverview( + new SearchedQueryOverview( + gExtensionStore.getController().getCurrentOverview(), + 0, + GExtensionStore.PAGESIZE, + storeRepository, + searchComponent.getSearchKeyword(), + searchComponent.getOrdering(), + searchComponent.getClients(), + searchComponent.getFrameworks(), + searchComponent.getCategories(), + false, + false + ) + ); } @Override diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/querying/ExtensionOrdering.java b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/querying/ExtensionOrdering.java index dd4be02..bf1f564 100644 --- a/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/querying/ExtensionOrdering.java +++ b/G-Earth/src/main/java/gearth/services/internal_extensions/extensionstore/repository/querying/ExtensionOrdering.java @@ -18,4 +18,13 @@ public enum ExtensionOrdering { public String getOrderName() { return orderName; } + + public static ExtensionOrdering fromString(String text) { + for (ExtensionOrdering b : ExtensionOrdering.values()) { + if (b.orderName.equalsIgnoreCase(text)) { + return b; + } + } + return null; + } } diff --git a/G-Earth/src/main/resources/gearth/services/internal_extensions/extensionstore/application/webview/css/add_item_layout.css b/G-Earth/src/main/resources/gearth/services/internal_extensions/extensionstore/application/webview/css/add_item_layout.css deleted file mode 100644 index e2a4706..0000000 --- a/G-Earth/src/main/resources/gearth/services/internal_extensions/extensionstore/application/webview/css/add_item_layout.css +++ /dev/null @@ -1,72 +0,0 @@ -.a_container { - margin: 0 2px 2px 2px; - background-color: #e9e9e1; - flex: 1 1 auto; - - display: flex; - flex-direction: column; - padding: 8px 3px 0 3px; -} - -.a_subcontainer { - flex: 1 1 auto; - display: flex; - flex-direction: column; -} - -.a_lbl { - flex: 0 0 auto; - color: white; - background-color: #3179ac; - height: 13px; - max-height: 13px; - - line-height: 13px; - font-size: 13px; - padding: 4px 3px; -} - -.a_txt { - border: none; - margin: 0; - padding: 2px 3px; - - overflow: auto; - outline: none; - - -webkit-box-shadow: none; - -moz-box-shadow: none; - box-shadow: none; - - resize: none; -} - - -.a_subject { - flex: 0 0 auto; - background-color: white; - height: 18px; - max-height: 18px; - overflow: hidden; - - font-size: 15px; - line-height: 21px; -} - -.a_div { - flex: 0 0 auto; - height: 6px; - max-height: 6px; -} - -.a_message { - flex: 1 1 auto; - background-color: white; -} - -#a_content_buttons { - flex: 0 0 38px; - margin: 13px 17px 13px 17px; - - display: flex; -} \ No newline at end of file diff --git a/G-Earth/src/main/resources/gearth/services/internal_extensions/extensionstore/application/webview/css/search.css b/G-Earth/src/main/resources/gearth/services/internal_extensions/extensionstore/application/webview/css/search.css new file mode 100644 index 0000000..3652a93 --- /dev/null +++ b/G-Earth/src/main/resources/gearth/services/internal_extensions/extensionstore/application/webview/css/search.css @@ -0,0 +1,55 @@ +.searchContainer { + + background-color: #d4eaf5; + + width: 100%; + min-height: 0; + + flex: 1; + overflow-y: auto; + +} + +.searchInnerContainer { + display: flex; + flex-direction: column; + min-width: 0; + + padding: 10px; + +} + +.centeredFlex { + /*justify-content: center;*/ + display: flex; + align-items: center +} + +.inputBox { + margin-left: 10px; +} + +.filterBox { + margin-right: 15px; + padding: 0 10px 10px 10px; + border: 1px solid #666; + border-radius: 5px; +} + +.filterStuff { + margin-top: 10px; + display: flex; + +} + +/*.searchFiller {*/ +/* flex: 1;*/ +/* margin-bottom: auto;*/ +/*}*/ + + +.searchInnerContainer p, .searchInnerContainer label { + margin: 8px 0; + color: #454545; + min-width: 0; +} diff --git a/G-Earth/src/main/resources/gearth/services/internal_extensions/extensionstore/application/webview/index.html b/G-Earth/src/main/resources/gearth/services/internal_extensions/extensionstore/application/webview/index.html index 24611ae..71a837a 100644 --- a/G-Earth/src/main/resources/gearth/services/internal_extensions/extensionstore/application/webview/index.html +++ b/G-Earth/src/main/resources/gearth/services/internal_extensions/extensionstore/application/webview/index.html @@ -2,7 +2,7 @@ - G-Forum + G-ExtensionStore @@ -12,6 +12,8 @@ + +