Skip to content

Commit

Permalink
Merge pull request #14 from ubigu/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
ossitammi committed Apr 26, 2024
2 parents 77e69c6 + 5f3ef4b commit c4c3ed0
Show file tree
Hide file tree
Showing 33 changed files with 395 additions and 96 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Test deployment

on:
push:
branches: [develop]
workflow_dispatch:

env:
IMAGE_NAME: ${{ secrets.TEST_REGISTRY_ADDRESS }}/vuorovaikutusalusta-test

jobs:
deploy:
name: Deploy to test
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.TEST_REGISTRY_ADDRESS }}
username: ${{ secrets.TEST_REGISTRY_USERNAME }}
password: ${{ secrets.TEST_REGISTRY_PASSWORD }}
- name: Build
uses: docker/build-push-action@v5
with:
push: true
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:latest
cache-to: type=inline
tags: ${{ env.IMAGE_NAME }}:latest
2 changes: 1 addition & 1 deletion client/src/components/SurveyLandingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export default function SurveyLandingPage({
<img
style={{
minWidth: '130px',
maxWidth: '20%',
width: '10vw',
position: !mediumWidth ? 'absolute' : 'static',
left: !mediumWidth ? '0' : 'auto',
bottom: 0,
Expand Down
22 changes: 20 additions & 2 deletions client/src/components/SurveyMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ interface Props {
pageId: number;
}

interface MapPosition {
centerX: number;
centerY: number;
zoom?: number;
options?: object;
}

export default function SurveyMap(props: Props) {
const [mapInitialized, setMapInitialized] = useState(false);
const [mapInitialPos, setMapiInitialPos] = useState<MapPosition | null>(null);
const iframeRef = useRef<HTMLIFrameElement>();
const {
rpcChannel,
Expand Down Expand Up @@ -75,13 +83,23 @@ export default function SurveyMap(props: Props) {

useEffect(() => {
if (!mapInitialized || !isMapReady) return;
if (!mapInitialPos) {
rpcChannel.getMapPosition((pos) => {
setMapiInitialPos(pos);
});
}

if (props.defaultMapView) {
centerToDefaultView(props.defaultMapView, {
fill: { color: '#00000000' },
stroke: { color: '#00000000' },
});
} else {
rpcChannel?.resetState(() => {});
} else if (mapInitialPos) {
rpcChannel.postRequest('MapMoveRequest', [
mapInitialPos.centerX,
mapInitialPos.centerY,
mapInitialPos.zoom,
]);
}
}, [props.defaultMapView, mapInitialized, props.pageId]);

Expand Down
14 changes: 8 additions & 6 deletions client/src/components/admin/ColorSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ export default function ColorSelect({ label, value, onChange }: Props) {

const colors = useMemo<{ name: string; value: string }[]>(
() => [
{ name: tr.ColorSelect.colors.black, value: '#000000' },
{ name: tr.ColorSelect.colors.darkGray, value: '#3f3e3e' },
{ name: tr.ColorSelect.colors.steelBlue, value: '#0074a4' },
{ name: tr.ColorSelect.colors.atmosphere, value: '#c83e36' },
{ name: tr.ColorSelect.colors.berryRed, value: '#ad3963' },
{ name: tr.ColorSelect.colors.warmGreen, value: '#418155' },
{ name: tr.ColorSelect.colors.teal, value: '#00a393' },
{ name: tr.ColorSelect.colors.sea, value: '#17607f' },
{ name: tr.ColorSelect.colors.sprig, value: '#1a776d' },
{ name: tr.ColorSelect.colors.grey, value: '#515b68' },
{ name: tr.ColorSelect.colors.night, value: '#001e39' },
{ name: tr.ColorSelect.colors.blue, value: '#0065BD' },
{ name: tr.ColorSelect.colors.earthRed, value: '#C84436' },
{ name: tr.ColorSelect.colors.tar, value: '#312322' },
],
[tr],
);
Expand Down
1 change: 1 addition & 0 deletions client/src/components/admin/EditDocumentSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function EditDocumentSection({ section, onChange }: Props) {
<FileUpload
surveyId={activeSurvey.id}
targetPath={[String(activeSurvey.id)]}
surveyGroups={activeSurvey.groups}
value={
!section.fileName
? null
Expand Down
1 change: 1 addition & 0 deletions client/src/components/admin/EditImageSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function EditImageSection({ section, onChange }: Props) {
<FileUpload
surveyId={activeSurvey.id}
targetPath={[String(activeSurvey.id)]}
surveyGroups={activeSurvey.groups}
value={
!section.fileName
? null
Expand Down
53 changes: 50 additions & 3 deletions client/src/components/admin/EditSurveyInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default function EditSurveyInfo() {
const [deleteConfirmDialogOpen, setDeleteConfirmDialogOpen] = useState(false);
const [deleteSurveyLoading, setDeleteSurveyLoading] = useState(false);
const [users, setUsers] = useState<User[]>(null);
const [currentUser, setCurrentUser] = useState<User>(null);
const [usersLoading, setUsersLoading] = useState(true);

const {
Expand All @@ -73,10 +74,14 @@ export default function EditSurveyInfo() {
async function fetchOtherUsers() {
setUsersLoading(true);
try {
const currentUser = await fetch('/api/users/me').then(
(response) => response.json() as Promise<User>,
);
const users = await fetch('/api/users/others').then(
(response) => response.json() as Promise<User[]>,
);
setUsers(users);
setCurrentUser(currentUser);
} catch (error) {
showToast({
severity: 'error',
Expand All @@ -89,6 +94,19 @@ export default function EditSurveyInfo() {
fetchOtherUsers();
}, []);

function getAllUsers() {
if (!currentUser || !activeSurvey || !users) {
return [];
}
const usersWithoutAuthor = users.filter(
(user) => user.id !== activeSurvey.authorId,
);
if (currentUser.id !== activeSurvey.authorId) {
return [...usersWithoutAuthor, currentUser];
}
return usersWithoutAuthor;
}

const localLanguage = useMemo(() => {
switch (language) {
case 'fi':
Expand Down Expand Up @@ -184,14 +202,42 @@ export default function EditSurveyInfo() {
tr.EditSurveyInfo.mapUrlError
}
/>
{!usersLoading && currentUser?.groups.length !== 1 && (
<Autocomplete
multiple
defaultValue={activeSurvey.groups}
disabled={usersLoading || currentUser.groups?.length === 1}
options={currentUser?.groups ?? []}
getOptionLabel={(group) => group}
value={activeSurvey.groups}
onChange={(_, value: string[]) => {
editSurvey({
...activeSurvey,
groups: value,
});
}}
renderInput={(params) => (
<TextField
{...params}
variant="standard"
label={tr.EditSurveyInfo.authorizedGroups}
helperText={tr.EditSurveyInfo.authorizedGroupsHelperText}
/>
)}
/>
)}

<Autocomplete
multiple
disabled={usersLoading}
options={users ?? []}
options={
users?.filter((user) => user.id !== activeSurvey.authorId) ?? []
}
getOptionLabel={(user) => user.fullName}
value={
users?.filter((user) => activeSurvey.admins?.includes(user.id)) ??
[]
getAllUsers()?.filter((user) =>
activeSurvey.admins?.includes(user.id),
) ?? []
}
onChange={(_, value: User[]) => {
editSurvey({
Expand All @@ -208,6 +254,7 @@ export default function EditSurveyInfo() {
/>
)}
/>

{availableMapLayersLoading && (
<Skeleton variant="rectangular" height={200} width="100%" />
)}
Expand Down
1 change: 1 addition & 0 deletions client/src/components/admin/EditSurveyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export default function EditSurveyPage() {
<FileUpload
surveyId={activeSurvey.id}
targetPath={[String(activeSurvey.id)]}
surveyGroups={activeSurvey.groups}
value={
!page.sidebar.imageName
? null
Expand Down
3 changes: 3 additions & 0 deletions client/src/components/admin/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface Props {
}[];
onUpload: (file: { name: string; path: string[] }) => void;
onDelete: (file: { name: string; path: string[] }) => void;
surveyGroups: string[];
}

export default function FileUpload({
Expand All @@ -23,6 +24,7 @@ export default function FileUpload({
value,
onDelete,
surveyId,
surveyGroups,
}: Props) {
const { tr } = useTranslations();
const { showToast } = useToasts();
Expand All @@ -34,6 +36,7 @@ export default function FileUpload({
const fullFilePath = getFullFilePath(path, name);
await fetch(`/api/file/${fullFilePath}`, {
method: 'DELETE',
headers: { groups: JSON.stringify(surveyGroups) },
});
}

Expand Down
1 change: 1 addition & 0 deletions client/src/components/admin/SurveyImageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ export default function SurveyImageList({ imageType, ...props }: Props) {
await fetch(getApiFilePath(imageType), {
method: 'POST',
body: formData,
headers: { groups: JSON.stringify(activeSurvey.groups) },
});
acceptedFiles.shift();
getImages();
Expand Down
3 changes: 2 additions & 1 deletion client/src/components/admin/SurveyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,15 @@ export default function SurveyList() {
setNewSurveyLoading(true);
try {
const newSurvey = await createNewSurvey();
setNewSurveyLoading(false);
history.push(`/kyselyt/${newSurvey.id}`);
} catch (error) {
showToast({
severity: 'error',
message: tr.SurveyList.errorCreatingNewSurvey,
});
} finally {
setNewSurveyLoading(false);
if (newSurveyLoading) setNewSurveyLoading(false);
}
}}
>
Expand Down
16 changes: 10 additions & 6 deletions client/src/stores/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
"nameHelperText": "The name displayed on the survey URL-address. This can only include characters (a-z), numbers (0-9), hyphen (-) and underline (_).",
"author": "Survey author / contact person",
"authorUnit": "Survey author's / contact person's unit",
"authorizedGroups": "Authorized user groups",
"authorizedGroupsHelperText": "Users in these groups will have access to the survey.",
"admins": "Survey admins",
"userFetchFailed": "Failed to fetch users. Try again later.",
"adminsHelperText": "Users besides the original author of the survey, who will have access to the survey answers and who can modify the survey.",
Expand Down Expand Up @@ -323,12 +325,14 @@
"ColorSelect": {
"color": "Color",
"colors": {
"black": "Black",
"darkGray": "Dark grey",
"steelBlue": "Steel blue",
"atmosphere": "Atmosphere",
"berryRed": "Berry red",
"warmGreen": "Warm green"
"teal": "Teal",
"sea": "Sea",
"sprig": "Sprig",
"grey": "Grey",
"night": "Night",
"blue": "Blue",
"earthRed": "Earth red",
"tar": "Tar"
}
},
"MarkerIconSelect": {
Expand Down
16 changes: 10 additions & 6 deletions client/src/stores/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
"nameHelperText": "Kyselyn URL-osoitteessa näkyvä nimi. Voi sisältää vain kirjaimia (a-z), numeroita (0-9) ja viivoja (- ja _).",
"author": "Kyselyn laatija/yhteyshenkilö",
"authorUnit": "Kyselyn laatijan yksikkö",
"authorizedGroups": "Luvitetut käyttäjäryhmät",
"authorizedGroupsHelperText": "Kyselyn näkevät vain valitut käyttäjäryhmät.",
"admins": "Kyselyn ylläpitäjät",
"userFetchFailed": "Käyttäjien haku epäonnistui. Yritä myöhemmin uudestaan.",
"adminsHelperText": "Kyselyn alkuperäisen luojan lisäksi määriteltävät käyttäjät, jotka voivat katsella kyselyn vastauksia sekä muokata kyselyä.",
Expand Down Expand Up @@ -323,12 +325,14 @@
"ColorSelect": {
"color": "Väri",
"colors": {
"black": "Musta",
"darkGray": "Tumma harmaa",
"steelBlue": "Teräksensininen",
"atmosphere": "Tunnelma",
"berryRed": "Marjanpunainen",
"warmGreen": "Lämmin vihreä"
"teal": "Tavi",
"sea": "Meri",
"sprig": "Havu",
"grey": "Harmaa",
"night": "",
"blue": "Sininen",
"earthRed": "Punamulta",
"tar": "Terva"
}
},
"MarkerIconSelect": {
Expand Down
16 changes: 10 additions & 6 deletions client/src/stores/se.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
"nameHelperText": "Namnet som syns i undersökningens URL-adress. Kan innehålla endast bokstäver (a-z), siffror (0-9) och bindestreck (- och _).",
"author": "Undersökningens författare/kontaktperson",
"authorUnit": "Författarens enhet",
"authorizedGroups": "Auktoriserade grupper",
"authorizedGroupsHelperText": "Endast utvalda användargrupper kan se enkäten.",
"admins": "Undersökningens administratörer",
"userFetchFailed": "Misslyckades att hämta användare. Försök igen senare.",
"adminsHelperText": "Användare som definieras förutom den ursprungliga skaparen av undersökningen, som kan se undersökningssvar och redigera undersökningen.",
Expand Down Expand Up @@ -322,12 +324,14 @@
"ColorSelect": {
"color": "Färg",
"colors": {
"black": "Svart",
"darkGray": "Mörkgrå",
"steelBlue": "Stålblå",
"atmosphere": "Atmosfär",
"berryRed": "Bärrotsröd",
"warmGreen": "Varmgrön"
"teal": "Tavi",
"sea": "Hav",
"sprig": "Grönskott",
"grey": "Grå",
"night": "Natt",
"blue": "Blå",
"earthRed": "Rödmylla",
"tar": "Tjära"
}
},
"MarkerIconSelect": {
Expand Down
Loading

0 comments on commit c4c3ed0

Please sign in to comment.